Skip to content

Commit

Permalink
fix(format): Allow git-attributes to be set to true (#384)
Browse files Browse the repository at this point in the history
Prior to this change, if one of the git attributes
used to disable format checks was set to a value
of `true`, it was still formatted since the only
valid syntax was setting the attribute without
any value.

After this change the attributes can be used without
a value or with the value of `true`
  • Loading branch information
mrmeku authored Sep 10, 2024
1 parent 43f62cc commit 5b004ff
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions docs/formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ Assuming you installed with the typical layout:
Commonly, the underlying formatters that rules_lint invokes provide their own methods of excluding files (.prettierignore for example). At times when that is not the case, rules_lint provides its
own escape hatch to exclude files from linting using attributes specified via [`.gitattributes` files](https://git-scm.com/docs/gitattributes).

If any of following attributes are set on a file it will be excluded:
If any of following attributes are set or have a value of `true` on a file it will be excluded:

- `rules-lint-ignored`
- `gitlab-generated`
- `linguist-generated`
- `rules-lint-ignored=true`
- `gitlab-generated=true`
- `linguist-generated=true`

### Install as a pre-commit hook

Expand Down
2 changes: 1 addition & 1 deletion format/private/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function ls-files {
fi

# Check if the attribute is set
if [[ "$line" == *"set" ]]; then
if [[ "$line" == *": set" || "$line" == *": true" ]]; then
attribute_set=true
fi
done <<< "$git_attributes"
Expand Down
4 changes: 2 additions & 2 deletions format/test/ls-files_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ kt=$(ls-files Kotlin)
# .gitattributes should allow more excludes
cat >.gitattributes <<EOF
gen1.js rules-lint-ignored
gen2.js rules-lint-ignored
gen2.js gitlab-generated
gen2.js rules-lint-ignored=false
gen2.js gitlab-generated=true
gen3.js linguist-generated
EOF
js=$(ls-files JavaScript)
Expand Down

0 comments on commit 5b004ff

Please sign in to comment.