-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add eslint flat config support (#132)
This adds support for ESLint's new flat config feature. There are now 3 exported configs: - `recommended` (legacy/eslintrc) - `best-practice` (legacy/eslintrc) - `flat/recommended` (flat) - `flat/best-practice` (flat) In future, we will drop the legacy ones and replace them with the flat configs in a breaking change.
- Loading branch information
Showing
7 changed files
with
105 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
const config = { | ||
extends: ['plugin:wc/recommended'], | ||
plugins: ['wc'], | ||
import type {ESLint, Linter} from 'eslint'; | ||
import {configFactory as recommendedFactory} from './recommended.js'; | ||
|
||
rules: { | ||
'wc/attach-shadow-constructor': 'error', | ||
'wc/guard-super-call': 'error', | ||
'wc/no-child-traversal-in-attributechangedcallback': 'error', | ||
'wc/no-child-traversal-in-connectedcallback': 'error', | ||
'wc/no-closed-shadow-root': 'error', | ||
'wc/no-constructor-params': 'error', | ||
'wc/no-customized-built-in-elements': 'error', | ||
'wc/no-invalid-extends': 'error', | ||
'wc/no-typos': 'error', | ||
'wc/require-listener-teardown': 'error' | ||
} | ||
export const configFactory = (plugin: ESLint.Plugin): Linter.FlatConfig => { | ||
const base = recommendedFactory(plugin); | ||
return { | ||
...base, | ||
rules: { | ||
...base.rules, | ||
'wc/attach-shadow-constructor': 'error', | ||
'wc/guard-super-call': 'error', | ||
'wc/no-child-traversal-in-attributechangedcallback': 'error', | ||
'wc/no-child-traversal-in-connectedcallback': 'error', | ||
'wc/no-closed-shadow-root': 'error', | ||
'wc/no-constructor-params': 'error', | ||
'wc/no-customized-built-in-elements': 'error', | ||
'wc/no-invalid-extends': 'error', | ||
'wc/no-typos': 'error', | ||
'wc/require-listener-teardown': 'error' | ||
} | ||
}; | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type {ESLint} from 'eslint'; | ||
|
||
export const config: ESLint.ConfigData = { | ||
extends: ['plugin:wc/recommended'], | ||
plugins: ['wc'], | ||
|
||
rules: { | ||
'wc/attach-shadow-constructor': 'error', | ||
'wc/guard-super-call': 'error', | ||
'wc/no-child-traversal-in-attributechangedcallback': 'error', | ||
'wc/no-child-traversal-in-connectedcallback': 'error', | ||
'wc/no-closed-shadow-root': 'error', | ||
'wc/no-constructor-params': 'error', | ||
'wc/no-customized-built-in-elements': 'error', | ||
'wc/no-invalid-extends': 'error', | ||
'wc/no-typos': 'error', | ||
'wc/require-listener-teardown': 'error' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type {ESLint} from 'eslint'; | ||
|
||
export const config: ESLint.ConfigData = { | ||
plugins: ['wc'], | ||
|
||
rules: { | ||
'wc/no-constructor-attributes': 'error', | ||
'wc/no-invalid-element-name': 'error', | ||
'wc/no-self-class': 'error' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
const config = { | ||
plugins: ['wc'], | ||
parserOptions: { | ||
sourceType: 'module' | ||
import type {ESLint, Linter} from 'eslint'; | ||
|
||
export const configFactory = (plugin: ESLint.Plugin): Linter.FlatConfig => ({ | ||
plugins: { | ||
wc: plugin | ||
}, | ||
|
||
rules: { | ||
'wc/no-constructor-attributes': 'error', | ||
'wc/no-invalid-element-name': 'error', | ||
'wc/no-self-class': 'error' | ||
} | ||
}; | ||
|
||
export default config; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type {ESLint, Linter} from 'eslint'; | ||
import {expect} from 'chai'; | ||
import {configs} from '../index'; | ||
|
||
type ConfigLike = Linter.FlatConfig | ESLint.ConfigData; | ||
|
||
const isFlatConfig = (config: ConfigLike): config is Linter.FlatConfig => | ||
!Array.isArray(config.plugins); | ||
|
||
describe('configs', () => { | ||
it('should define configs correctly', () => { | ||
expect(configs['recommended']).to.be.ok; | ||
expect(configs['best-practice']).to.be.ok; | ||
expect(configs['flat/recommended']).to.be.ok; | ||
expect(configs['flat/best-practice']).to.be.ok; | ||
|
||
expect(isFlatConfig(configs['flat/recommended'])).to.equal(true); | ||
expect(isFlatConfig(configs['flat/best-practice'])).to.equal(true); | ||
expect(isFlatConfig(configs['recommended'])).to.equal(false); | ||
expect(isFlatConfig(configs['best-practice'])).to.equal(false); | ||
}); | ||
}); |