aspect-build / aspect-build/rules_lint

[FR]: Allow .gitattributes to contribute format language patterns

Open
#912 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Starlark
Stars
155
Forks
125
Avg merge
3d 21h
Merged PRs (30d)
20

Description

### What is the current behavior?

Formatting relies on hardcoded patterns for languages in `format/private/format.sh`. Users who wish to customize the language patterns, perhaps to register an internal convention for a file pattern must patch this file.

In our case, we use an OWNERS file format based on the [Kubernetes convention](https://www.kubernetes.dev/docs/guide/owners/) and register `OWNERS` as a `YAML` pattern with the following patch:

```
diff --git a/format/private/format.sh b/format/private/format.sh
index 7d4d7fadab..9a68ab848b 100755
--- a/format/private/format.sh
+++ b/format/private/format.sh
@@ -147,7 +147,7 @@
'TSX') patterns=('*.tsx') ;;
'TypeScript') patterns=('*.ts' '*.cts' '*.mts') ;;
'Vue') patterns=('*.vue') ;;
- 'YAML') patterns=('*.yml' '*.yaml' '.clang-format' '.clang-tidy' '.gemrc') ;;
+ 'YAML') patterns=('*.yml' '*.yaml' '.clang-format' '.clang-tidy' '.gemrc' 'OWNERS') ;;
# Note: https://github.com/github-linguist/linguist/blob/559a6426942abcae16b6d6b328147476432bf6cb/lib/linguist/languages.yml#L7767-L7882
# has a giant list of patterns. We arbitrarily choose some "common" ones.
'XML') patterns=('*.xml' '*.xsd') ;;
```

This patch wouldn't be appropriate to upstream, so we're left indefinitely maintaining a patch on top of `rules_lint` releases.

### Describe the feature

Users with the above use case are likely already managing these file associations in `.gitattributes` for GitHub syntax highlighting. In our case, for the OWNERS example, we have the folllowing in our `.gitattributes` file:

```
OWNERS linguist-language=YAML
```

The feature request would be to update `format/private/format.sh` to query `.gitattributes` for language patterns in `ls-files` to avoid patching the script.

The format script already queries `.gitattributes` for `rules-lint-ignored`, so this change would be in the spirit of the existing implementation and would also honor the `disable_git_attribute_checks` flag.

I propose that we support two conventions for git attributes:
1. A new `rules-lint-language` attribute for users who wish to be explicit
2. Repurpose the existing `linguist-language` to automatically opt-in GitHub language mappings

Contributor guide

Open the contributing guide

Research direction

Start in format/private/format.sh, especially the existing .gitattributes query for rules-lint-ignored and the handling of disable_git_attribute_checks. Trace how language patterns are selected from ls-files, then determine how rules-lint-language and linguist-language should contribute mappings. Done means user-defined patterns such as OWNERS can be formatted without patching the script while the existing disable flag is honored.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, shell
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.