From 3f912e669fd17f79343b2af4a334ab49a149886c Mon Sep 17 00:00:00 2001 From: Joseph Phelan Date: Thu, 11 Jul 2024 09:50:17 -0500 Subject: [PATCH] update workflows, imports --- .github/workflows/build.yml | 12 +-- .github/workflows/format.yml | 4 +- README.md | 40 +++++--- packages/eslint-config-widen/package.json | 8 +- packages/eslint-config-widen/src/base.ts | 97 +++++++++++++++++ packages/eslint-config-widen/src/index.ts | 120 +++++----------------- 6 files changed, 154 insertions(+), 127 deletions(-) create mode 100644 packages/eslint-config-widen/src/base.ts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5baba8c..19325f8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,8 +4,8 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: 20.x cache: yarn @@ -19,9 +19,9 @@ jobs: matrix: node-version: [18.x, 20.x] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} cache: yarn @@ -32,10 +32,10 @@ jobs: needs: [lint, test] if: github.ref == 'refs/heads/main' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: node-version: 20.x cache: yarn diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 1495e7e..932ba63 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -6,8 +6,8 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: 20.x - run: yarn install --immutable diff --git a/README.md b/README.md index b821aa9..f883f2c 100644 --- a/README.md +++ b/README.md @@ -25,21 +25,27 @@ yarn add -D eslint-plugin-jest ## Usage -In your `.eslintrc` file, add the following four entries to your extends list. -If you don't need a specific configuration, simply remove it from the list. - -```json -{ - "extends": ["widen", "widen/typescript", "widen/react"], - "overrides": [ - { - "files": ["e2e/**"], - "extends": "widen/playwright" - }, - { - "files": ["frontend/**"], - "extends": "widen/jest" - } - ] -} +In your `eslint.config.mjs` file, add the following four entries to your extends +list. If you don't need a specific configuration, simply remove it from the +list. + +```js +import { base, typescript, react, playwright, jest } from 'eslint-config-widen' + +export default [ + // Base Widen configurations + ...base, + ...typescript, + ...react, + + // Overrides for specific directories + { + files: ['e2e/**'], + ...playwright, + }, + { + files: ['frontend/**'], + ...jest, + }, +] ``` diff --git a/packages/eslint-config-widen/package.json b/packages/eslint-config-widen/package.json index 13e3856..e9914b8 100644 --- a/packages/eslint-config-widen/package.json +++ b/packages/eslint-config-widen/package.json @@ -5,11 +5,7 @@ }, "description": "Widen's shared ESLint config.", "exports": { - ".": "./lib/index.js", - "./jest": "./lib/jest.js", - "./playwright": "./lib/playwright.js", - "./react": "./lib/react.js", - "./typescript": "./lib/typescript.js" + ".": "./lib/index.js" }, "files": [ "lib" @@ -21,7 +17,7 @@ "@babel/eslint-parser": "^7.22.15", "@typescript-eslint/eslint-plugin": "^6.9.1", "@typescript-eslint/parser": "^6.9.1", - "eslint": ">= 8", + "eslint": ">= 9", "eslint-plugin-jest": ">= 27", "eslint-plugin-jsx-a11y": ">= 6", "eslint-plugin-playwright": ">=0.16.0", diff --git a/packages/eslint-config-widen/src/base.ts b/packages/eslint-config-widen/src/base.ts new file mode 100644 index 0000000..54771e4 --- /dev/null +++ b/packages/eslint-config-widen/src/base.ts @@ -0,0 +1,97 @@ +import babelParser from '@babel/eslint-parser' +import js from '@eslint/js' +import sort from 'eslint-plugin-sort' +import widen from 'eslint-plugin-widen' +import globals from 'globals' + +export default [ + { + languageOptions: { + globals: { + ...globals.browser, + ...globals.es6, + ...globals.jest, + ...globals.node, + }, + parser: babelParser, + parserOptions: { + requireConfigFile: false, + }, + }, + plugins: { + sort, + widen, + }, + rules: { + 'default-param-last': 'error', + 'dot-notation': 'error', + eqeqeq: [ + 'error', + 'always', + { + null: 'ignore', + }, + ], + 'no-console': ['error', { allow: ['error'] }], + 'no-dupe-args': 'error', + 'no-duplicate-imports': 'error', + 'no-else-return': 'error', + 'no-empty': ['error', { allowEmptyCatch: true }], + 'no-extra-bind': 'error', + 'no-param-reassign': 'error', + 'no-return-await': 'error', + 'no-template-curly-in-string': 'error', + 'no-unneeded-ternary': 'error', + 'no-unused-expressions': 'off', + 'no-unused-vars': [ + 'error', + { + ignoreRestSiblings: true, + varsIgnorePattern: '^_', + }, + ], + 'no-useless-computed-key': 'error', + 'no-var': 'error', + 'object-shorthand': 'error', + 'prefer-const': [ + 'error', + { + destructuring: 'all', + }, + ], + 'require-await': 'error', + 'sort/exports': [ + 'warn', + { + groups: [ + { order: 6, type: 'default' }, + { order: 5, type: 'sourceless' }, + { order: 2, regex: '^@widen\\/' }, + { order: 4, regex: '^\\.+' }, + { order: 1, type: 'dependency' }, + { order: 3, type: 'other' }, + ], + }, + ], + 'sort/imports': [ + 'warn', + { + groups: [ + { order: 1, type: 'side-effect' }, + { order: 3, regex: '^@widen\\/' }, + { order: 5, regex: '^\\.+' }, + { order: 2, type: 'dependency' }, + { order: 4, type: 'other' }, + ], + }, + ], + }, + }, + js.configs.recommended, + { + files: ['**/*.js', '**/*.mjs'], + rules: { + 'prettier/prettier': 'error', // Assuming you have `eslint-plugin-prettier` setup + }, + }, +] diff --git a/packages/eslint-config-widen/src/index.ts b/packages/eslint-config-widen/src/index.ts index 54771e4..7a487f8 100644 --- a/packages/eslint-config-widen/src/index.ts +++ b/packages/eslint-config-widen/src/index.ts @@ -1,97 +1,25 @@ -import babelParser from '@babel/eslint-parser' -import js from '@eslint/js' -import sort from 'eslint-plugin-sort' -import widen from 'eslint-plugin-widen' -import globals from 'globals' +// index.js or index.mjs inside eslint-config-widen package +import baseConfig from './index.js' +import typescriptConfig from './typescript.js' +import reactConfig from './react.js' +import playwrightConfig from './playwright.js' +import jestConfig from './jest.js' +import { Linter } from 'eslint' -export default [ - { - languageOptions: { - globals: { - ...globals.browser, - ...globals.es6, - ...globals.jest, - ...globals.node, - }, - parser: babelParser, - parserOptions: { - requireConfigFile: false, - }, - }, - plugins: { - sort, - widen, - }, - rules: { - 'default-param-last': 'error', - 'dot-notation': 'error', - eqeqeq: [ - 'error', - 'always', - { - null: 'ignore', - }, - ], - 'no-console': ['error', { allow: ['error'] }], - 'no-dupe-args': 'error', - 'no-duplicate-imports': 'error', - 'no-else-return': 'error', - 'no-empty': ['error', { allowEmptyCatch: true }], - 'no-extra-bind': 'error', - 'no-param-reassign': 'error', - 'no-return-await': 'error', - 'no-template-curly-in-string': 'error', - 'no-unneeded-ternary': 'error', - 'no-unused-expressions': 'off', - 'no-unused-vars': [ - 'error', - { - ignoreRestSiblings: true, - varsIgnorePattern: '^_', - }, - ], - 'no-useless-computed-key': 'error', - 'no-var': 'error', - 'object-shorthand': 'error', - 'prefer-const': [ - 'error', - { - destructuring: 'all', - }, - ], - 'require-await': 'error', - 'sort/exports': [ - 'warn', - { - groups: [ - { order: 6, type: 'default' }, - { order: 5, type: 'sourceless' }, - { order: 2, regex: '^@widen\\/' }, - { order: 4, regex: '^\\.+' }, - { order: 1, type: 'dependency' }, - { order: 3, type: 'other' }, - ], - }, - ], - 'sort/imports': [ - 'warn', - { - groups: [ - { order: 1, type: 'side-effect' }, - { order: 3, regex: '^@widen\\/' }, - { order: 5, regex: '^\\.+' }, - { order: 2, type: 'dependency' }, - { order: 4, type: 'other' }, - ], - }, - ], - }, - }, - js.configs.recommended, - { - files: ['**/*.js', '**/*.mjs'], - rules: { - 'prettier/prettier': 'error', // Assuming you have `eslint-plugin-prettier` setup - }, - }, -] +export interface EslintConfig { + base: Linter.FlatConfig[] + typescript: Linter.FlatConfig[] + react: Linter.FlatConfig[] + playwright: Linter.FlatConfig[] + jest: Linter.FlatConfig[] +} + +const configs = { + base: baseConfig, + typescript: typescriptConfig, + react: reactConfig, + playwright: playwrightConfig, + jest: jestConfig, +} as unknown as EslintConfig + +export default configs