diff --git a/.eslintrc b/.eslintrc index ae05460..5fa69fa 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,10 +4,11 @@ "parserOptions": { "project": ["./tsconfig.json"] }, - "plugins": ["@typescript-eslint", "sonarjs"], + "plugins": ["@typescript-eslint", "sonarjs", "filename-rules"], "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:sonarjs/recommended"], "ignorePatterns": ["**/*.js"], "rules": { + "filename-rules/match": [2, "/^(e2e\\.ts$|.*\/e2e\\.ts$|[a-z0-9]+(?:[-._a-z0-9]+)*\\.ts|\\.[a-z0-9]+)$/"], "prefer-arrow-callback": ["warn", { "allowNamedFunctions": true }], "func-style": ["warn", "declaration", { "allowArrowFunctions": false }], "@typescript-eslint/no-floating-promises": "error", @@ -40,16 +41,16 @@ "sonarjs/no-identical-expressions": "error", "@typescript-eslint/naming-convention": [ "error", - { "selector": "interface", "format": ["PascalCase"], "custom": { "regex": "^I[A-Z]", "match": false } }, - { "selector": "memberLike", "modifiers": ["private"], "format": ["camelCase"], "leadingUnderscore": "require" }, - { "selector": "typeLike", "format": ["PascalCase"] }, - { "selector": "typeParameter", "format": ["PascalCase"], "prefix": ["T"] }, - { "selector": "variable", "format": ["camelCase", "UPPER_CASE"], "leadingUnderscore": "allow", "trailingUnderscore": "allow" }, - { "selector": "variable", "format": ["camelCase"], "leadingUnderscore": "allow", "trailingUnderscore": "allow" }, + { "selector": "interface", "format": ["StrictPascalCase"], "custom": { "regex": "^I[A-Z]", "match": false } }, + { "selector": "memberLike", "modifiers": ["private"], "format": ["strictCamelCase"], "leadingUnderscore": "require" }, + { "selector": "typeLike", "format": ["StrictPascalCase"] }, + { "selector": "typeParameter", "format": ["StrictPascalCase"], "prefix": ["T"] }, + { "selector": "variable", "format": ["strictCamelCase", "UPPER_CASE"], "leadingUnderscore": "allow", "trailingUnderscore": "allow" }, + { "selector": "variable", "format": ["strictCamelCase"], "leadingUnderscore": "allow", "trailingUnderscore": "allow" }, { "selector": "variable", "modifiers": ["destructured"], "format": null }, - { "selector": "variable", "types": ["boolean"], "format": ["PascalCase"], "prefix": ["is", "should", "has", "can", "did", "will", "does"] }, - { "selector": "variableLike", "format": ["camelCase"] }, - { "selector": ["function", "variable"], "format": ["camelCase"] } + { "selector": "variable", "types": ["boolean"], "format": ["StrictPascalCase"], "prefix": ["is", "should", "has", "can", "did", "will", "does"] }, + { "selector": "variableLike", "format": ["strictCamelCase"] }, + { "selector": ["function", "variable"], "format": ["strictCamelCase"] } ] } } diff --git a/.github/workflows/knip-reporter.yml b/.github/workflows/knip-reporter.yml new file mode 100644 index 0000000..cf58ea8 --- /dev/null +++ b/.github/workflows/knip-reporter.yml @@ -0,0 +1,38 @@ +name: Knip-reporter + +on: + workflow_run: + workflows: ["Knip"] + types: + - completed + +jobs: + knip-reporter: + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + name: knip-results + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Read pr number + id: pr-number + uses: juliangruber/read-file-action@v1 + with: + path: ./pr-number.txt + trim: true + + - name: Report knip results to pull request + if: ${{ github.event.workflow_run.conclusion != 'success' }} + uses: gitcoindev/knip-reporter@main + with: + verbose: true + comment_id: ${{ github.workflow }}-reporter + command_script_name: knip-ci + annotations: true + ignore_results: false + json_input: true + json_input_file_name: knip-results.json + pull_request_number: ${{ steps.pr-number.outputs.content }} + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/knip.yml b/.github/workflows/knip.yml index 50a1a2a..809976b 100644 --- a/.github/workflows/knip.yml +++ b/.github/workflows/knip.yml @@ -1,10 +1,7 @@ name: Knip on: - pull_request_target: - workflow_dispatch: - -permissions: write-all + pull_request: jobs: run-knip: @@ -13,6 +10,10 @@ jobs: - name: Checkout uses: actions/checkout@v4 + # needed to use yarn v4 + - name: Enable corepack + run: corepack enable + - name: Setup Node uses: actions/setup-node@v4 with: @@ -21,11 +22,17 @@ jobs: - name: Install toolchain run: yarn install - - name: Report knip results to pull request - uses: Codex-/knip-reporter@v2 + - name: Store PR number + run: echo ${{ github.event.number }} > pr-number.txt + + - name: Run Knip + run: yarn knip || yarn knip --reporter json > knip-results.json + + - name: Upload knip result + if: failure() + uses: actions/upload-artifact@v4 with: - verbose: true - comment_id: ${{ github.workflow }}-reporter - command_script_name: knip-ci - annotations: true - ignore_results: false + name: knip-results + path: | + knip-results.json + pr-number.txt diff --git a/package.json b/package.json index 675b097..ec1b4ae 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "esbuild": "^0.20.1", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", + "eslint-plugin-filename-rules": "^1.3.1", "eslint-plugin-prettier": "^5.1.3", "eslint-plugin-sonarjs": "^0.24.0", "husky": "^9.0.11", diff --git a/yarn.lock b/yarn.lock index aca8c12..0c43b39 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3376,6 +3376,11 @@ eslint-config-prettier@^9.1.0: resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz#31af3d94578645966c082fcb71a5846d3c94867f" integrity sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw== +eslint-plugin-filename-rules@^1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-filename-rules/-/eslint-plugin-filename-rules-1.3.1.tgz#8fb769f2c19dc832b43c13d76c1442bca4a2f4a4" + integrity sha512-kBMxGFvK3QrRBHMurhFSNa+PFdszezVtBV6egg39TDzlj6D4jL3Xx6oyNjm5xE4C+TdQUBzWwymHJHBPyxOreA== + eslint-plugin-prettier@^5.1.3: version "5.1.3" resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-5.1.3.tgz#17cfade9e732cef32b5f5be53bd4e07afd8e67e1"