Skip to content

Commit

Permalink
Fix config and update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
joephela committed Jul 12, 2024
1 parent 9df6cfa commit 426b1db
Show file tree
Hide file tree
Showing 24 changed files with 1,853 additions and 105 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-monkeys-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-config-widen': patch
---

Fix config and update examples.
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,20 @@ 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'
import { base, react, jest, playwright, typescript } from 'eslint-config-widen'

export default [
// Base Widen configurations
base,
typescript,
react,

// Overrides for specific directories
{
files: ['e2e/**'],
...playwright,
},
{
files: ['frontend/**'],
...base,
...typescript,
...react,
...[
// you can specify what to ignore by using the `ignores` key before any other rule
// this will filter out things we dont want this to run on
{ ignores: ['*.test.*'] },
...jest,
},
// you can also override rules by specifying the rule and the new value
{ files: ['*.spec.js'], rules: { 'jest/expect-expect': 'off' } },
],
...[{ files: ['e2e/**'] }, ...playwright],
]
```
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const compat = new FlatCompat({

export default [
{
ignores: ['**/lib/'],
ignores: ['**/lib/', '**/packages/eslint-playground/'],
},
...compat.extends(
'eslint:recommended',
Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('@jest/types').Config.ProjectConfig} */
module.exports = {
testPathIgnorePatterns: ['<rootDir>/packages/eslint-playground/'],
}
26 changes: 12 additions & 14 deletions packages/eslint-config-widen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,20 @@ 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'
import { base, react, jest, playwright, typescript } from 'eslint-config-widen'

export default [
// Base Widen configurations
base,
typescript,
react,

// Overrides for specific directories
{
files: ['e2e/**'],
...playwright,
},
{
files: ['frontend/**'],
...base,
...typescript,
...react,
...[
// you can specify what to ignore by using the `ignores` key before any other rule
// this will filter out things we dont want this to run on
{ ignores: ['*.test.*'] },
...jest,
},
// you can also override rules by specifying the rule and the new value
{ files: ['*.spec.js'], rules: { 'jest/expect-expect': 'off' } },
],
...[{ files: ['e2e/**'] }, ...playwright],
]
```
1 change: 1 addition & 0 deletions packages/eslint-config-widen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"files": [
"lib"
],
"type": "module",
"homepage": "https://github.com/Widen/eslint-config/tree/master/packages/eslint-config-widen#readme",
"license": "ISC",
"name": "eslint-config-widen",
Expand Down
17 changes: 8 additions & 9 deletions packages/eslint-config-widen/src/base.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import js from '@eslint/js'
import prettier from 'eslint-plugin-prettier'
import sort from 'eslint-plugin-sort'
import widen from 'eslint-plugin-widen'

Check warning on line 4 in packages/eslint-config-widen/src/base.ts

View workflow job for this annotation

GitHub Actions / lint

Imports should be sorted
import globals from 'globals'
import babelParser from '@babel/eslint-parser'
import sharedGlobals from './sharedGlobals.js'

export default [
{
languageOptions: {
globals: {
...globals.browser,
...globals.es6,
...globals.jest,
...globals.node,
},
globals: sharedGlobals,
parser: babelParser,
parserOptions: {
requireConfigFile: false,
},
},
plugins: {
prettier,
sort,
widen,
},
Expand Down Expand Up @@ -89,9 +86,11 @@ export default [
},
js.configs.recommended,
{
files: ['**/*.js', '**/*.mjs'],
plugins: {
prettier,
},
rules: {
'prettier/prettier': 'error', // Assuming you have `eslint-plugin-prettier` setup
...prettier.configs.recommended.rules,
},
},
]
30 changes: 6 additions & 24 deletions packages/eslint-config-widen/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
// index.js or index.mjs inside eslint-config-widen package
import { Linter } from 'eslint'
import baseConfig from './index.js'
import jestConfig from './jest.js'
import playwrightConfig from './playwright.js'
import reactConfig from './react.js'
import typescriptConfig from './typescript.js'
import base from './base.js'
import jest from './jest.js'
import playwright from './playwright.js'
import react from './react.js'
import typescript from './typescript.js'

export interface EslintConfig {
base: Linter.FlatConfig[]
typescript: Linter.FlatConfig[]
react: Linter.FlatConfig[]
playwright: Linter.FlatConfig[]
jest: Linter.FlatConfig[]
}

const configs = {
base: baseConfig,
jest: jestConfig,
playwright: playwrightConfig,
react: reactConfig,
typescript: typescriptConfig,
} as unknown as EslintConfig

export default configs
export { base, jest, playwright, react, typescript }
9 changes: 8 additions & 1 deletion packages/eslint-config-widen/src/playwright.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import playwright from 'eslint-plugin-playwright'

delete playwright.configs['playwright-test'].env

export default [
{
plugins: {
Expand Down Expand Up @@ -32,5 +34,10 @@ export default [
'playwright/require-top-level-describe': 'warn',
},
},
playwright.configs['playwright-test'],
{
...playwright.configs['playwright-test'],
plugins: {
playwright,
},
},
]
52 changes: 46 additions & 6 deletions packages/eslint-config-widen/src/react.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,66 @@
import eslintJsxA11y from 'eslint-plugin-jsx-a11y'
import eslintReact from 'eslint-plugin-react'
import eslintReactHooks from 'eslint-plugin-react-hooks'
import jsxA11y from 'eslint-plugin-jsx-a11y'
import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
import sharedGlobals from './sharedGlobals.js'

const languageOptions = {
globals: sharedGlobals,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
}

export default [
eslintReact.configs.recommended,
eslintReactHooks.configs.recommended,
eslintJsxA11y.configs.recommended,
{
files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
languageOptions,
plugins: {
react,
},
rules: {
...react.configs.recommended.rules,
},
},
{
files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
languageOptions,
plugins: {
'react-hooks': reactHooks,
},
rules: {
...reactHooks.configs.recommended.rules,
},
},
{
files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
languageOptions,
plugins: {
'jsx-a11y': jsxA11y,
},
rules: {
...jsxA11y.configs.recommended.rules,
},
},
{
files: ['*.tsx', '*.{spec,test}.{js,jsx}'],
languageOptions,
rules: {
'react/prop-types': 'off',
},
},
{
files: ['*.{spec,test}.{tsx,js,jsx}'],
languageOptions,
rules: {
'react/button-has-type': 'off',
'react/display-name': 'off',
},
},
{
files: ['*.tsx', '*.{spec,test}.{js,jsx}'],
languageOptions,
rules: {
'jsx-a11y/click-events-have-key-events': 'warn',
'jsx-a11y/label-has-associated-control': [
Expand Down
14 changes: 14 additions & 0 deletions packages/eslint-config-widen/src/sharedGlobals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import globals from 'globals'

// delete an invalid global that causes error because of the trailing space
const browser = globals.browser
delete browser['AudioWorkletGlobalScope ']

const sharedGlobals = {
...browser,
...globals.es6,
...globals.node,
...globals.jest,
}

export default sharedGlobals
1 change: 1 addition & 0 deletions packages/eslint-config-widen/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ declare module 'eslint-plugin-sort'
declare module 'eslint-plugin-widen'
declare module '@babel/eslint-parser'
declare module 'eslint-plugin-playwright'
declare module 'eslint-plugin-prettier'
2 changes: 1 addition & 1 deletion packages/eslint-config-widen/src/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import tseslint from 'typescript-eslint'

export default [
tseslint.configs.recommended,
...tseslint.configs.recommended,
{
files: ['*.ts', '*.tsx'],
languageOptions: {
Expand Down
8 changes: 7 additions & 1 deletion packages/eslint-config-widen/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
"rootDir": "src",
"module": "esnext",
"esModuleInterop": true,
"target": "es2016"
},
"paths": {
"@/*": ["./src/*"]
}
}
11 changes: 11 additions & 0 deletions packages/eslint-playground/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# eslint-playground

A sample project that uses the eslint-config-widen to ensure things are working.
Included is a file to correspond with each eslint plugin type which will throw
lint errors.

### To test updates:

1. Run `yarn ts` in the base package any time you change the code in the
eslint-config-widen to regen the output.
2. In the eslint-playground package run `yarn lint`
11 changes: 11 additions & 0 deletions packages/eslint-playground/e2e/sample.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect, test } from 'fixtures'

/**
* Basic test with errors to test playwright eslint config
*/
test.describe('Sample', () => {
test('should pass', async ({ page }) => {
console.log('wow')
await page.goto('https://playwright.dev/')
})
})
16 changes: 16 additions & 0 deletions packages/eslint-playground/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { base, react, jest, playwright, typescript } from 'eslint-config-widen'

export default [
...base,
...typescript,
...react,
...[
// you can specify what to ignore by using the `ignores` key before any other rule
// this will filter out things we dont want this to run on
{ ignores: ['*.test.*'] },
...jest,
// you can also override rules by specifying the rule and the new value
{ files: ['*.spec.js'], rules: { 'jest/expect-expect': 'off' } },
],
...[{ files: ['e2e/**'] }, ...playwright],
]
6 changes: 6 additions & 0 deletions packages/eslint-playground/hey.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Empty test to test jest eslint config errors
*/
it('should render', async () => {
console.log('hey')
})
10 changes: 10 additions & 0 deletions packages/eslint-playground/jsTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* contains some failing rules to test base eslint config
*/
export function test(input = 'test', hey) {
try {
console.log('test')
} catch (e) {
throw e
}
}
24 changes: 24 additions & 0 deletions packages/eslint-playground/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "eslint-playground",
"packageManager": "[email protected]",
"scripts": {
"lint": "eslint ."
},
"devDependencies": {
"@babel/core": "^7.24.8",
"@babel/eslint-parser": "^7.24.8",
"eslint": "^9.6.0",
"eslint-config-widen": "workspace:^",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-jsx-a11y": "^6.9.0",
"eslint-plugin-playwright": "^1.6.2",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.3",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-sort": "^3.0.2",
"eslint-plugin-widen": "workspace:^"
},
"dependencies": {
"react": "^18.3.1"
}
}
6 changes: 6 additions & 0 deletions packages/eslint-playground/reactTest.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react'

export function test(unused, unused) {
console.log('wow')
return <button>Test</button>
}
Loading

0 comments on commit 426b1db

Please sign in to comment.