Skip to content

Commit

Permalink
Add lint/format CI checks (#43)
Browse files Browse the repository at this point in the history
* Add lint/format CI checks

* Add eslint config file and packages

* Add prettier dependency and config

* Fix formatting in config files

* test changed file check

* fix lint and format error in changed source file
  • Loading branch information
jasongwartz authored Apr 1, 2024
1 parent cdb40c1 commit 8dea8a2
Show file tree
Hide file tree
Showing 7 changed files with 407 additions and 119 deletions.
42 changes: 42 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-env node */
module.exports = {
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "simple-import-sort"],

parserOptions: {
project: true,
},

extends: [
"plugin:@typescript-eslint/strict-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"prettier",
],

rules: {
"@typescript-eslint/consistent-type-imports": "error",
"simple-import-sort/imports": "error",
camelcase: ["error", { properties: "always" }],
eqeqeq: ["error", "always"],
"prefer-const": "error",
"@typescript-eslint/no-throw-literal": "error",
"@typescript-eslint/switch-exhaustiveness-check": "error",
// Specifically allow "_" as a placeholder argument name
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_$" }],
},

overrides: [
{
files: ["./*.js", "./*.mjs"], // config files
env: { node: true },
extends: ["plugin:@typescript-eslint/disable-type-checked"],
rules: {
"@typescript-eslint/no-var-requires": "off",
},
},
{
files: ["**/*.test.ts"],
plugins: ["jest"],
},
],
};
53 changes: 53 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: lint

on:
pull_request:
branches: [main]

permissions:
contents: read
pull-requests: read

jobs:
eslint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
cache: "npm"

- run: npm ci

- name: Run eslint on changed files
uses: tj-actions/eslint-changed-files@v20
with:
reporter: github-check
token: ${{ secrets.GITHUB_TOKEN }}

prettier:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
cache: "npm"

- run: npm ci

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v38

- run: npx prettier --check ${{ steps.changed-files.outputs.all_changed_files }}

actionlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check workflow files
uses: docker://rhysd/actionlint:latest
with:
args: -color
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- name: Run tests
run: |
tests=$(find ./codegen/src/ -name '*.test.pkl')
# shellcheck disable=SC2086
pkl test $tests
pkl-snippet:
Expand Down
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false,
"printWidth": 100
}
Loading

0 comments on commit 8dea8a2

Please sign in to comment.