Skip to content

Commit 9c14dee

Browse files
committed
chore: add recipes for linting commit messages
1 parent 1867584 commit 9c14dee

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

tools/make/lib/lint/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
include $(TOOLS_MAKE_LIB_DIR)/lint/c/Makefile
2323
include $(TOOLS_MAKE_LIB_DIR)/lint/conf/Makefile
2424
include $(TOOLS_MAKE_LIB_DIR)/lint/filenames.mk
25+
include $(TOOLS_MAKE_LIB_DIR)/lint/git/Makefile
2526
include $(TOOLS_MAKE_LIB_DIR)/lint/javascript/Makefile
2627
include $(TOOLS_MAKE_LIB_DIR)/lint/julia/Makefile
2728
include $(TOOLS_MAKE_LIB_DIR)/lint/license-headers/Makefile

tools/make/lib/lint/git/Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2023 The Stdlib Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#/
18+
19+
# DEPENDENCIES #
20+
21+
# Note: keep in alphabetical order...
22+
include $(TOOLS_MAKE_LIB_DIR)/lint/git/commitlint.mk
23+
24+
25+
# RULES #
26+
27+
#/
28+
# Lints commit messages.
29+
#
30+
# @example
31+
# make lint-commit
32+
#/
33+
lint-commit:
34+
ifeq ($(GIT_COMMIT_LINTER), commitlint)
35+
$(QUIET) $(MAKE) -f $(this_file) commitlint
36+
endif
37+
38+
.PHONY: lint-commit
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2023 The Stdlib Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#/
18+
19+
# VARIABLES #
20+
21+
# Define the path to the [commitlint][1] executable.
22+
#
23+
# To install commitlint:
24+
#
25+
# ```bash
26+
# $ npm install commitlint
27+
# ```
28+
#
29+
# [1]: https://github.com/conventional-changelog/commitlint
30+
COMMITLINT ?= $(BIN_DIR)/commitlint
31+
32+
# Define the command-line options to be used when invoking the executable:
33+
COMMITLINT_FLAGS ?= \
34+
--cwd "$(ROOT_DIR)" \
35+
--config "$(CONFIG_DIR)/commitlint/.commitlintrc.js" \
36+
--edit
37+
38+
39+
# RULES #
40+
41+
#/
42+
# Lints a commit message.
43+
#
44+
# ## Notes
45+
#
46+
# - We have to temporarily move the `tsconfig` file, as `commitlint` (erroneously) attempts to use the file for compiling TypeScript.
47+
#
48+
# @private
49+
#
50+
# @example
51+
# make commitlint
52+
#/
53+
commitlint: $(NODE_MODULES)
54+
$(QUIET) mv $(ROOT_DIR)/tsconfig.json $(ROOT_DIR)/tsconfig.json.tmp
55+
$(QUIET) NODE_PATH="$(NODE_PATH)" $(NODE) "$(COMMITLINT)" $(COMMITLINT_FLAGS) || (mv $(ROOT_DIR)/tsconfig.json.tmp $(ROOT_DIR)/tsconfig.json && exit 1)
56+
$(QUIET) mv $(ROOT_DIR)/tsconfig.json.tmp $(ROOT_DIR)/tsconfig.json
57+
58+
.PHONY: commitlint

0 commit comments

Comments
 (0)