-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for flat config (#708)
- Loading branch information
Showing
12 changed files
with
379 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"eslint-plugin-svelte": minor | ||
--- | ||
|
||
feat: add support for flat 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
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,18 @@ | ||
import { rules } from '../../utils/rules'; | ||
import base from './base'; | ||
export default [ | ||
...base, | ||
{ | ||
rules: Object.fromEntries( | ||
rules | ||
.map((rule) => [`svelte/${rule.meta.docs.ruleName}`, 'error']) | ||
.filter( | ||
([ruleName]) => | ||
![ | ||
// Does not work without options. | ||
'svelte/no-restricted-html-elements' | ||
].includes(ruleName) | ||
) | ||
) | ||
} | ||
]; |
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,30 @@ | ||
// IMPORTANT! | ||
// This file has been automatically generated, | ||
// in order to update its content execute "pnpm run update" | ||
import type { ESLint } from 'eslint'; | ||
export default [ | ||
{ | ||
files: ['*.svelte', '**/*.svelte'], | ||
plugins: { | ||
get svelte(): ESLint.Plugin { | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore | ||
return require('../../index'); | ||
} | ||
}, | ||
languageOptions: { | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore | ||
parser: require('svelte-eslint-parser') | ||
}, | ||
rules: { | ||
// ESLint core rules known to cause problems with `.svelte`. | ||
'no-inner-declarations': 'off', // The AST generated by svelte-eslint-parser will false positives in it rule because the root node of the script is not the `Program`. | ||
// "no-irregular-whitespace": "off", | ||
// Self assign is one of way to update reactive value in Svelte. | ||
'no-self-assign': 'off', | ||
|
||
// eslint-plugin-svelte rules | ||
'svelte/comment-directive': 'error', | ||
'svelte/system': '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,23 @@ | ||
// IMPORTANT! | ||
// This file has been automatically generated, | ||
// in order to update its content execute "pnpm run update" | ||
import base from './base'; | ||
export default [ | ||
...base, | ||
{ | ||
rules: { | ||
// eslint-plugin-svelte rules | ||
'svelte/first-attribute-linebreak': 'off', | ||
'svelte/html-closing-bracket-spacing': 'off', | ||
'svelte/html-quotes': 'off', | ||
'svelte/html-self-closing': 'off', | ||
'svelte/indent': 'off', | ||
'svelte/max-attributes-per-line': 'off', | ||
'svelte/mustache-spacing': 'off', | ||
'svelte/no-spaces-around-equal-signs-in-attribute': 'off', | ||
'svelte/no-trailing-spaces': 'off', | ||
'svelte/shorthand-attribute': 'off', | ||
'svelte/shorthand-directive': 'off' | ||
} | ||
} | ||
]; |
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,26 @@ | ||
// IMPORTANT! | ||
// This file has been automatically generated, | ||
// in order to update its content execute "pnpm run update" | ||
import base from './base'; | ||
export default [ | ||
...base, | ||
{ | ||
rules: { | ||
// eslint-plugin-svelte rules | ||
'svelte/comment-directive': 'error', | ||
'svelte/no-at-debug-tags': 'warn', | ||
'svelte/no-at-html-tags': 'error', | ||
'svelte/no-dupe-else-if-blocks': 'error', | ||
'svelte/no-dupe-style-properties': 'error', | ||
'svelte/no-dynamic-slot-name': 'error', | ||
'svelte/no-inner-declarations': 'error', | ||
'svelte/no-not-function-handler': 'error', | ||
'svelte/no-object-in-text-mustaches': 'error', | ||
'svelte/no-shorthand-style-property-overrides': 'error', | ||
'svelte/no-unknown-style-directive-property': 'error', | ||
'svelte/no-unused-svelte-ignore': 'error', | ||
'svelte/system': 'error', | ||
'svelte/valid-compile': '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
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,58 @@ | ||
import assert from 'assert'; | ||
import semver from 'semver'; | ||
import plugin from '../../../src/index'; | ||
import { LegacyESLint, ESLint } from '../../utils/eslint-compat'; | ||
|
||
describe('`all` config', () => { | ||
it('legacy `all` config should work. ', async () => { | ||
const code = `<script>const a = 1, b = 2;</script>{@html a+b}`; | ||
|
||
const linter = new LegacyESLint({ | ||
plugins: { | ||
svelte: plugin as never | ||
}, | ||
baseConfig: { | ||
parserOptions: { | ||
ecmaVersion: 2020 | ||
}, | ||
extends: ['plugin:svelte/recommended'] | ||
}, | ||
useEslintrc: false | ||
}); | ||
const result = await linter.lintText(code, { filePath: 'test.svelte' }); | ||
const messages = result[0].messages; | ||
|
||
assert.deepStrictEqual( | ||
messages.map((m) => ({ ruleId: m.ruleId, line: m.line, message: m.message })), | ||
[ | ||
{ | ||
ruleId: 'svelte/no-at-html-tags', | ||
message: '`{@html}` can lead to XSS attack.', | ||
line: 1 | ||
} | ||
] | ||
); | ||
}); | ||
it('`all` config should work. ', async () => { | ||
if (semver.satisfies(ESLint.version, '<8.0.0')) return; | ||
const code = `<script>const a = 1, b = 2;</script>{@html a+b}`; | ||
|
||
const linter = new ESLint({ | ||
overrideConfigFile: true as never, | ||
overrideConfig: plugin.configs['flat/recommended'] as never | ||
}); | ||
const result = await linter.lintText(code, { filePath: 'test.svelte' }); | ||
const messages = result[0].messages; | ||
|
||
assert.deepStrictEqual( | ||
messages.map((m) => ({ ruleId: m.ruleId, line: m.line, message: m.message })), | ||
[ | ||
{ | ||
ruleId: 'svelte/no-at-html-tags', | ||
message: '`{@html}` can lead to XSS attack.', | ||
line: 1 | ||
} | ||
] | ||
); | ||
}); | ||
}); |
Oops, something went wrong.