Skip to content

Commit

Permalink
update workflows, imports
Browse files Browse the repository at this point in the history
  • Loading branch information
joephela committed Jul 11, 2024
1 parent 0426491 commit 3f912e6
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 127 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 23 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
]
```
8 changes: 2 additions & 6 deletions packages/eslint-config-widen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down
97 changes: 97 additions & 0 deletions packages/eslint-config-widen/src/base.ts
Original file line number Diff line number Diff line change
@@ -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
},
},
]
120 changes: 24 additions & 96 deletions packages/eslint-config-widen/src/index.ts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3f912e6

Please sign in to comment.