Skip to content

Commit

Permalink
Setup Trunk as a meta-linter for the repo
Browse files Browse the repository at this point in the history
Configures buildifier to run with a config obtained from removing
docstring and 'sorted items in dict' warnings from the example config.
```
.trunk/tools/buildifier -config=example
```
  • Loading branch information
Siddhartha Bagaria committed Sep 12, 2023
1 parent 0f21054 commit 07541b9
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .buildifier.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"type": "auto",
"mode": "fix",
"lint": "fix",
"warningsList": [
"attr-applicable_licenses",
"attr-cfg",
"attr-license",
"attr-licenses",
"attr-non-empty",
"attr-output-default",
"attr-single-file",
"build-args-kwargs",
"bzl-visibility",
"confusing-name",
"constant-glob",
"ctx-actions",
"ctx-args",
"deprecated-function",
"depset-items",
"depset-iteration",
"depset-union",
"dict-concatenation",
"dict-method-named-arg",
"duplicated-name",
"filetype",
"git-repository",
"http-archive",
"integer-division",
"keyword-positional-params",
"list-append",
"load",
"load-on-top",
"name-conventions",
"native-android",
"native-build",
"native-cc",
"native-java",
"native-package",
"native-proto",
"native-py",
"no-effect",
"out-of-order-load",
"output-group",
"overly-nested-depset",
"package-name",
"package-on-top",
"positional-args",
"print",
"provider-params",
"redefined-variable",
"repository-name",
"return-value",
"rule-impl-return",
"same-origin-load",
"skylark-comment",
"skylark-docstring",
"string-iteration",
"uninitialized",
"unnamed-macro",
"unreachable",
"unused-variable"
]
}
25 changes: 25 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Pull Request
on: [pull_request]
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

# NOTE: This current setup does not post annotations to PRs.
# https://github.com/marketplace/actions/trunk-check#getting-inline-annotations-for-fork-prs

permissions: read-all

jobs:
trunk_check:
name: Trunk Check Runner
runs-on: ubuntu-latest
permissions:
checks: write # For trunk to post annotations
contents: read # For repo checkout

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Trunk Check
uses: trunk-io/trunk-action@v1
8 changes: 8 additions & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*out
*logs
*actions
*notifications
*tools
plugins
user_trunk.yaml
user.yaml
10 changes: 10 additions & 0 deletions .trunk/configs/.markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Autoformatter friendly markdownlint config (all formatting rules disabled)
default: true
blank_lines: false
bullet: false
html: false
indentation: false
line_length: false
spaces: false
url: false
whitespace: false
7 changes: 7 additions & 0 deletions .trunk/configs/.shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enable=all
source-path=SCRIPTDIR
disable=SC2154

# If you're having issues with shellcheck following source, disable the errors via:
# disable=SC1090
# disable=SC1091
10 changes: 10 additions & 0 deletions .trunk/configs/.yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
rules:
quoted-strings:
required: only-when-needed
extra-allowed: ["{|}"]
empty-values:
forbid-in-block-mappings: true
forbid-in-flow-mappings: true
key-duplicates: {}
octal-values:
forbid-implicit-octal: true
64 changes: 64 additions & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
version: 0.1
cli:
version: 1.15.0
plugins:
sources:
- id: trunk
ref: v1.2.3
uri: https://github.com/trunk-io/plugins
runtimes:
enabled:
- [email protected]
- [email protected]
- [email protected]
lint:
definitions:
- name: buildifier
files: [starlark, bazel-build, bazel-workspace]
tools: [buildifier]
commands:
- name: fix
run: buildifier --lint=fix "${target}"
output: rewrite
cache_results: true
formatter: true
in_place: true
batch: true
success_codes: [0]
- name: warn
run: buildifier --lint=warn --format=json --mode=check "${target}"
# Custom parser type defined in the trunk cli to handle buildifier's JSON output.
output: buildifier
cache_results: true
batch: true
success_codes: [0]
suggest_if: files_present
direct_configs:
- .buildifier.json
# Not a native buildifier construct, but useful for 'addTables', see test file
- .buildifier-tables.json
environment:
- name: PATH
list: ["${linter}"]
known_good_version: 6.1.0
version_command:
parse_regex: ${semver}
run: buildifier --version
enabled:
- [email protected]
- [email protected]
- [email protected]
- git-diff-check
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
actions:
enabled:
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
- trunk-upgrade-available
1 change: 1 addition & 0 deletions tests/.buildifier.json

0 comments on commit 07541b9

Please sign in to comment.