eslint-plugin-svelte 3.21.0 → 3.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/lib/main.d.ts +1 -1
- package/lib/meta.d.ts +1 -1
- package/lib/meta.js +1 -1
- package/lib/rule-types.d.ts +5 -0
- package/lib/rules/no-conflicting-module-names.d.ts +2 -0
- package/lib/rules/no-conflicting-module-names.js +104 -0
- package/lib/utils/rules.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -297,6 +297,7 @@ These rules relate to possible syntax or logic errors in Svelte code:
|
|
|
297
297
|
|:--------|:------------|:---|
|
|
298
298
|
| [svelte/infinite-reactive-loop](https://sveltejs.github.io/eslint-plugin-svelte/rules/infinite-reactive-loop/) | Svelte runtime prevents calling the same reactive statement twice in a microtask. But between different microtask, it doesn't prevent. | :star: |
|
|
299
299
|
| [svelte/no-bind-value-on-checkable-inputs](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-bind-value-on-checkable-inputs/) | disallow useless `bind:value` on `<input type="checkbox">` and `<input type="radio">` | :bulb: |
|
|
300
|
+
| [svelte/no-conflicting-module-names](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-conflicting-module-names/) | disallow a `.svelte` component and a same-named runes module (e.g. `Foo.svelte` and `Foo.svelte.ts`) from coexisting | |
|
|
300
301
|
| [svelte/no-dom-manipulating](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dom-manipulating/) | disallow DOM manipulating | :star: |
|
|
301
302
|
| [svelte/no-dupe-else-if-blocks](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dupe-else-if-blocks/) | disallow duplicate conditions in `{#if}` / `{:else if}` chains | :star: |
|
|
302
303
|
| [svelte/no-dupe-on-directives](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dupe-on-directives/) | disallow duplicate `on:` directives | :star: |
|
package/lib/main.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare const configs: {
|
|
|
14
14
|
export declare const rules: Record<string, Rule.RuleModule>;
|
|
15
15
|
export declare const meta: {
|
|
16
16
|
name: "eslint-plugin-svelte";
|
|
17
|
-
version: "3.
|
|
17
|
+
version: "3.22.0";
|
|
18
18
|
};
|
|
19
19
|
export declare const processors: {
|
|
20
20
|
'.svelte': typeof processor;
|
package/lib/meta.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name: "eslint-plugin-svelte";
|
|
2
|
-
export declare const version: "3.
|
|
2
|
+
export declare const version: "3.22.0";
|
package/lib/meta.js
CHANGED
package/lib/rule-types.d.ts
CHANGED
|
@@ -120,6 +120,11 @@ export interface RuleOptions {
|
|
|
120
120
|
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-bind-value-on-checkable-inputs/
|
|
121
121
|
*/
|
|
122
122
|
'svelte/no-bind-value-on-checkable-inputs'?: Linter.RuleEntry<[]>;
|
|
123
|
+
/**
|
|
124
|
+
* disallow a `.svelte` component and a same-named runes module (e.g. `Foo.svelte` and `Foo.svelte.ts`) from coexisting
|
|
125
|
+
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-conflicting-module-names/
|
|
126
|
+
*/
|
|
127
|
+
'svelte/no-conflicting-module-names'?: Linter.RuleEntry<[]>;
|
|
123
128
|
/**
|
|
124
129
|
* disallow DOM manipulating
|
|
125
130
|
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dom-manipulating/
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createRule } from '../utils/index.js';
|
|
4
|
+
// Extensions that plain TypeScript resolution appends to an unknown `.svelte`
|
|
5
|
+
// specifier. `.d.ts` is intentionally excluded: `Foo.svelte.d.ts` is a
|
|
6
|
+
// hand-written component declaration and does not shadow the component.
|
|
7
|
+
const MODULE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mts', '.cts', '.mjs', '.cjs'];
|
|
8
|
+
function isFile(filePath) {
|
|
9
|
+
try {
|
|
10
|
+
return fs.statSync(filePath).isFile();
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Resolve the real on-disk casing of a path's basename. On case-insensitive
|
|
17
|
+
// file systems (macOS, Windows) `fs.statSync` matches a differently-cased
|
|
18
|
+
// sibling, so the constructed name may not exist with that exact casing. Read
|
|
19
|
+
// the directory and use the actual entry name when one matches.
|
|
20
|
+
function realBasename(filePath) {
|
|
21
|
+
const wanted = path.basename(filePath);
|
|
22
|
+
try {
|
|
23
|
+
const entries = fs.readdirSync(path.dirname(filePath));
|
|
24
|
+
return (entries.find((entry) => entry === wanted) ??
|
|
25
|
+
entries.find((entry) => entry.toLowerCase() === wanted.toLowerCase()) ??
|
|
26
|
+
wanted);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return wanted;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export default createRule('no-conflicting-module-names', {
|
|
33
|
+
meta: {
|
|
34
|
+
docs: {
|
|
35
|
+
description: 'disallow a `.svelte` component and a same-named runes module (e.g. `Foo.svelte` and `Foo.svelte.ts`) from coexisting',
|
|
36
|
+
category: 'Possible Errors',
|
|
37
|
+
recommended: false
|
|
38
|
+
},
|
|
39
|
+
schema: [],
|
|
40
|
+
messages: {
|
|
41
|
+
conflictOnComponent: 'The module `{{moduleName}}` has the same name as this component. TypeScript resolves the import `{{specifier}}` to that module, not to this component. Rename `{{moduleName}}`.',
|
|
42
|
+
conflictOnModule: 'This module has the same name as the component `{{svelteName}}`. TypeScript resolves the import `{{specifier}}` to this module, not to the component. Rename this file.'
|
|
43
|
+
},
|
|
44
|
+
type: 'problem'
|
|
45
|
+
},
|
|
46
|
+
create(context) {
|
|
47
|
+
const filename = context.physicalFilename;
|
|
48
|
+
// Skip virtual/untitled files that do not exist on disk (editors, tests
|
|
49
|
+
// with fake paths). Only real files on disk are checked.
|
|
50
|
+
if (!isFile(filename)) {
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
// Both sides of the collision are linted by this plugin, and a lint run
|
|
54
|
+
// may contain only one of them, so each side reports on itself.
|
|
55
|
+
if (filename.endsWith('.svelte')) {
|
|
56
|
+
return {
|
|
57
|
+
Program(node) {
|
|
58
|
+
const svelteName = path.basename(filename);
|
|
59
|
+
for (const ext of MODULE_EXTENSIONS) {
|
|
60
|
+
const modulePath = `${filename}${ext}`;
|
|
61
|
+
if (isFile(modulePath)) {
|
|
62
|
+
context.report({
|
|
63
|
+
node,
|
|
64
|
+
loc: { line: 1, column: 0 },
|
|
65
|
+
messageId: 'conflictOnComponent',
|
|
66
|
+
data: {
|
|
67
|
+
moduleName: realBasename(modulePath),
|
|
68
|
+
specifier: `./${svelteName}`
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// A module named `<name>.svelte.<ext>`. Dropping the extension gives the
|
|
78
|
+
// component path it collides with. Declaration files such as
|
|
79
|
+
// `Foo.svelte.d.ts` do not match, because dropping `.ts` leaves
|
|
80
|
+
// `Foo.svelte.d`, which is not a component name.
|
|
81
|
+
const moduleExt = MODULE_EXTENSIONS.find((ext) => filename.endsWith(ext));
|
|
82
|
+
if (moduleExt == null) {
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
85
|
+
const sveltePath = filename.slice(0, -moduleExt.length);
|
|
86
|
+
if (!sveltePath.endsWith('.svelte') || !isFile(sveltePath)) {
|
|
87
|
+
return {};
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
Program(node) {
|
|
91
|
+
const svelteName = realBasename(sveltePath);
|
|
92
|
+
context.report({
|
|
93
|
+
node,
|
|
94
|
+
loc: { line: 1, column: 0 },
|
|
95
|
+
messageId: 'conflictOnModule',
|
|
96
|
+
data: {
|
|
97
|
+
svelteName,
|
|
98
|
+
specifier: `./${svelteName}`
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
});
|
package/lib/utils/rules.js
CHANGED
|
@@ -21,6 +21,7 @@ import noAtConstTags from '../rules/no-at-const-tags.js';
|
|
|
21
21
|
import noAtDebugTags from '../rules/no-at-debug-tags.js';
|
|
22
22
|
import noAtHtmlTags from '../rules/no-at-html-tags.js';
|
|
23
23
|
import noBindValueOnCheckableInputs from '../rules/no-bind-value-on-checkable-inputs.js';
|
|
24
|
+
import noConflictingModuleNames from '../rules/no-conflicting-module-names.js';
|
|
24
25
|
import noDomManipulating from '../rules/no-dom-manipulating.js';
|
|
25
26
|
import noDupeElseIfBlocks from '../rules/no-dupe-else-if-blocks.js';
|
|
26
27
|
import noDupeOnDirectives from '../rules/no-dupe-on-directives.js';
|
|
@@ -106,6 +107,7 @@ export const rules = [
|
|
|
106
107
|
noAtDebugTags,
|
|
107
108
|
noAtHtmlTags,
|
|
108
109
|
noBindValueOnCheckableInputs,
|
|
110
|
+
noConflictingModuleNames,
|
|
109
111
|
noDomManipulating,
|
|
110
112
|
noDupeElseIfBlocks,
|
|
111
113
|
noDupeOnDirectives,
|