File tree Expand file tree Collapse file tree 5 files changed +78
-18
lines changed Expand file tree Collapse file tree 5 files changed +78
-18
lines changed Original file line number Diff line number Diff line change @@ -9,22 +9,7 @@ if echo "$stdin" | grep -q "^(delete)"; then
9
9
exit 0
10
10
fi
11
11
12
- current_branch_name=" $( git branch --show-current) "
13
-
14
- if [[ " $current_branch_name " == " main" ]]; then
15
- raw_files_to_check=" $( git diff origin/main...HEAD --name-only --diff-filter=d) "
16
- else
17
- raw_files_to_check=" $( git diff main...HEAD --name-only --diff-filter=d) "
18
- fi
19
-
20
- if [[ -n " $raw_files_to_check " ]]; then
21
- echo " *** Checking for lint violations in changed files ***************"
22
- echo
23
-
24
- echo " $raw_files_to_check " | while IFS=$' \n ' read -r line; do
25
- printf ' %s\0' " $line "
26
- done | xargs -0 yarn prettier --check --ignore-unknown || exit $?
27
- fi
12
+ scripts/lint-changed-files.sh --check
28
13
29
14
echo
30
15
echo " *** Auditing dependencies ***************"
Original file line number Diff line number Diff line change @@ -93,6 +93,12 @@ yarn lint:fix
93
93
Provided that you ran ` bin/setup ` above,
94
94
any code you've changed will also be linted
95
95
whenever you push a commit.
96
+ If this step fails for any reason,
97
+ you can fix lint violations in only changed files by running:
98
+
99
+ ```
100
+ yarn lint:changed:fix
101
+ ```
96
102
97
103
[ prettier-editors ] : https://prettier.io/docs/en/editors.html
98
104
Original file line number Diff line number Diff line change 5
5
"private" : true ,
6
6
"scripts" : {
7
7
"audit" : " yarn npm audit && bundle exec bundle audit --gemfile-lock ${BUNDLE_GEMFILE:-Gemfile}" ,
8
- "lint" : " prettier --check ." ,
9
- "lint:fix" : " yarn lint --write" ,
8
+ "lint" : " scripts/lint-all-files.sh --check" ,
9
+ "lint:fix" : " scripts/lint-all-files.sh --write" ,
10
+ "lint:changed" : " scripts/lint-changed-files.sh --include-uncommitted --check" ,
11
+ "lint:changed:fix" : " scripts/lint-changed-files.sh --include-uncommitted --write" ,
10
12
"setup-git-hooks" : " husky install"
11
13
},
12
14
"devDependencies" : {
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ exec prettier " $@ " .
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ get-files-to-lint () {
4
+ local flag=" $1 "
5
+ local current_branch_name=" $( git branch --show-current) "
6
+
7
+ if [[ " $current_branch_name " == " main" ]]; then
8
+ git diff origin/main...HEAD --name-only --diff-filter=d
9
+ else
10
+ git diff main...HEAD --name-only --diff-filter=d
11
+ fi
12
+
13
+ if [[ $flag == " --include-uncommitted" ]]; then
14
+ git diff --name-only --diff-filter=d
15
+ fi
16
+ }
17
+
18
+ main () {
19
+ local prettier_flag
20
+ local include_uncommitted_flag
21
+
22
+ while [[ -n " $1 " ]]; do
23
+ case " $1 " in
24
+ --check | --write)
25
+ prettier_flag=" $1 "
26
+ shift
27
+ ;;
28
+ --include-uncommitted)
29
+ include_uncommitted_flag=" $1 "
30
+ shift
31
+ ;;
32
+ * )
33
+ echo " ERROR: Unknown option $1 ."
34
+ exit 1
35
+ ;;
36
+ esac
37
+ done
38
+
39
+ local files_to_lint=" $( get-files-to-lint " $include_uncommitted_flag " ) "
40
+
41
+ if [[ -z " $prettier_flag " ]]; then
42
+ echo " ERROR: Missing --check or --write."
43
+ exit 1
44
+ fi
45
+
46
+ echo " *** Checking for lint violations in changed files ***************"
47
+ echo
48
+
49
+ if [[ -n " $files_to_lint " ]]; then
50
+ echo " Files to check:"
51
+ echo " $files_to_lint " | while IFS=$' \n ' read -r line; do
52
+ echo " - $line "
53
+ done
54
+
55
+ echo
56
+ echo " $files_to_lint " | while IFS=$' \n ' read -r line; do
57
+ printf ' %s\0' " $line "
58
+ done | xargs -0 yarn prettier " $prettier_flag " --ignore-unknown
59
+ else
60
+ echo " No files to lint this time."
61
+ fi
62
+ }
63
+
64
+ main " $@ "
You can’t perform that action at this time.
0 commit comments