Skip to content

Commit

Permalink
Add ast-grep GitHub Action (#68540)
Browse files Browse the repository at this point in the history
This uses the official ast-grep GitHub Action [0] to run our ast-grep
lints on changes.

Test Plan: CI

[0] https://github.com/ast-grep/action
  • Loading branch information
wbinnssmith authored and ForsakenHarmony committed Aug 16, 2024
1 parent 0c5a2e3 commit 4e7b4ef
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 18 deletions.
20 changes: 6 additions & 14 deletions .config/ast-grep/rules/no-context.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.json

id: no-context
message: Don't name variables `context`.
note: Use a more specific name, such as chunking_context, asset_context, etc.
Expand All @@ -19,17 +21,7 @@ rule:
- inside:
kind: field_declaration
ignores:
- './crates/turbopack-css/**'
- './crates/turbopack-dev-server/**'
- './crates/turbopack-browser/**'
- './crates/turbopack-ecmascript-hmr-protocol/**'
- './crates/turbopack-ecmascript-plugins/**'
- './crates/turbopack-ecmascript-runtime/**'
- './crates/turbopack-json/**'
- './crates/turbopack-mdx/**'
- './crates/turbopack-node/**'
- './crates/turbopack-static/**'
- './crates/turbopack-tests/**'
- './crates/turbopack/**'
- './crates/turborepo-cache/**'
- './crates/turborepo-scm/**'
# These are ignored so we can fix these cases incrementally. They will
# gradually be fixed and removed from this list.
- 'crates/next-api/**/*.rs'
- 'crates/next-core/**/*.rs'
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ build/** linguist-generated=false
turbopack/crates/turbo-tasks-macros-tests/tests/**/*.stderr linguist-generated=true
turbopack/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/**/output.md linguist-generated=true
turbopack/crates/turbopack-tests/tests/snapshot/**/output/** linguist-generated=true

.config/ast-grep/rule-tests/__snapshots__/** linguist-generated=true
11 changes: 11 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ jobs:
stepName: 'rust-doc-check'
secrets: inherit

ast-grep:
needs: ['changes', 'build-next']
runs-on: ubuntu-latest
name: ast-grep lint
steps:
- uses: actions/checkout@v4
- name: ast-grep lint step
uses: ast-grep/[email protected]
with:
version: 0.25.6

devlow-bench:
name: Run devlow benchmarks
needs: ['changes', 'build-next', 'build-native']
Expand Down
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"usernamehw.errorlens",
"ast-grep.ast-grep-vscode",

// Testing
"orta.vscode-jest",
Expand Down
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,10 @@
"scheme": "file"
}
],
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"gitlens.advanced.blame.customArguments": [
"--ignore-revs-file",
"${workspaceRoot}/.git-blame-ignore-revs"
],
"astGrep.serverPath": "node_modules/@ast-grep/cli/ast-grep"
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
"typescript": "tsc --noEmit",
"lint-typescript": "turbo run typescript",
"lint-eslint": "eslint . --ext js,jsx,ts,tsx --config .eslintrc.cli.json --no-eslintrc",
"lint-ast-grep": "ast-grep scan",
"lint-no-typescript": "run-p prettier-check lint-eslint lint-language",
"types-and-precompiled": "run-p lint-typescript check-precompiled validate-externals-doc",
"validate-externals-doc": "node ./scripts/validate-externals-doc.js",
"lint": "run-p test-types lint-typescript prettier-check lint-eslint lint-language",
"lint": "run-p test-types lint-typescript prettier-check lint-eslint lint-ast-grep lint-language",
"lint-fix": "pnpm prettier-fix && pnpm lint-eslint --fix",
"lint-language": "alex .",
"prettier-check": "prettier --check .",
Expand All @@ -64,6 +65,7 @@
},
"devDependencies": {
"@actions/core": "1.10.1",
"@ast-grep/cli": "0.25.6",
"@babel/core": "7.22.5",
"@babel/eslint-parser": "7.22.5",
"@babel/generator": "7.22.5",
Expand Down
86 changes: 84 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sgconfig.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/project.json

ruleDirs:
- .config/ast-grep/rules
testConfigs:
Expand Down

0 comments on commit 4e7b4ef

Please sign in to comment.