Skip to content

Commit f31eb27

Browse files
committed
dfeat: add svelte/no-svete-internal
1 parent 60e784e commit f31eb27

File tree

10 files changed

+112
-0
lines changed

10 files changed

+112
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ These rules relate to better ways of doing things to help you avoid problems:
385385
| [svelte/no-inline-styles](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-inline-styles/) | disallow attributes and directives that produce inline styles | |
386386
| [svelte/no-reactive-functions](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-reactive-functions/) | it's not necessary to define functions in reactive statements | :bulb: |
387387
| [svelte/no-reactive-literals](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-reactive-literals/) | don't assign literal values in reactive statements | :bulb: |
388+
| [svelte/no-svelte-internal](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-svelte-internal/) | svelte/internal will be removed in Svelte 6. | |
388389
| [svelte/no-unused-class-name](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unused-class-name/) | disallow the use of a class in the template without a corresponding style | |
389390
| [svelte/no-unused-svelte-ignore](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unused-svelte-ignore/) | disallow unused svelte-ignore comments | :star: |
390391
| [svelte/no-useless-mustaches](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-useless-mustaches/) | disallow unnecessary mustache interpolations | :wrench: |

docs/rules.md

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ These rules relate to better ways of doing things to help you avoid problems:
5858
| [svelte/no-inline-styles](./rules/no-inline-styles.md) | disallow attributes and directives that produce inline styles | |
5959
| [svelte/no-reactive-functions](./rules/no-reactive-functions.md) | it's not necessary to define functions in reactive statements | :bulb: |
6060
| [svelte/no-reactive-literals](./rules/no-reactive-literals.md) | don't assign literal values in reactive statements | :bulb: |
61+
| [svelte/no-svelte-internal](./rules/no-svelte-internal.md) | svelte/internal will be removed in Svelte 6. | |
6162
| [svelte/no-unused-class-name](./rules/no-unused-class-name.md) | disallow the use of a class in the template without a corresponding style | |
6263
| [svelte/no-unused-svelte-ignore](./rules/no-unused-svelte-ignore.md) | disallow unused svelte-ignore comments | :star: |
6364
| [svelte/no-useless-mustaches](./rules/no-useless-mustaches.md) | disallow unnecessary mustache interpolations | :wrench: |

docs/rules/no-svelte-internal.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
pageClass: 'rule-details'
3+
sidebarDepth: 0
4+
title: 'svelte/no-svelte-internal'
5+
description: 'svelte/internal will be removed in Svelte 6.'
6+
---
7+
8+
# svelte/no-svelte-internal
9+
10+
> svelte/internal will be removed in Svelte 6.
11+
12+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> **_This rule has not been released yet._** </badge>
13+
14+
## :book: Rule Details
15+
16+
This rule reports ???.
17+
18+
<ESLintCodeBlock>
19+
20+
<!--eslint-skip-->
21+
22+
```svelte
23+
<script>
24+
/* eslint svelte/no-svelte-internal: "error" */
25+
</script>
26+
27+
<!-- ✓ GOOD -->
28+
29+
<!-- ✗ BAD -->
30+
```
31+
32+
</ESLintCodeBlock>
33+
34+
## :wrench: Options
35+
36+
```json
37+
{
38+
"svelte/no-svelte-internal": ["error", {}]
39+
}
40+
```
41+
42+
-
43+
44+
## :books: Further Reading
45+
46+
-
47+
48+
## :mag: Implementation
49+
50+
- [Rule source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/src/rules/no-svelte-internal.ts)
51+
- [Test source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/tests/src/rules/no-svelte-internal.ts)

src/rule-types.ts

+5
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ export interface RuleOptions {
209209
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-store-async/
210210
*/
211211
'svelte/no-store-async'?: Linter.RuleEntry<[]>
212+
/**
213+
* svelte/internal will be removed in Svelte 6.
214+
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-svelte-internal/
215+
*/
216+
'svelte/no-svelte-internal'?: Linter.RuleEntry<[]>
212217
/**
213218
* disallow `target="_blank"` attribute without `rel="noopener noreferrer"`
214219
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-target-blank/

src/rules/no-svelte-internal.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { createRule } from '../utils';
2+
3+
export default createRule('no-svelte-internal', {
4+
meta: {
5+
docs: {
6+
description: 'svelte/internal will be removed in Svelte 6.',
7+
category: 'Best Practices',
8+
// TODO Switch to recommended in the major version.
9+
// recommended: true,
10+
recommended: false
11+
},
12+
schema: [],
13+
messages: {
14+
unexpected: 'Importing from svelte/internal is prohibited. This will be removed in Svelte 6.'
15+
},
16+
type: 'problem'
17+
},
18+
create(context) {
19+
return {
20+
ImportDeclaration(node) {
21+
if (node.source.value === 'svelte/internal') {
22+
context.report({
23+
node,
24+
messageId: 'unexpected'
25+
});
26+
}
27+
}
28+
};
29+
}
30+
});

src/utils/rules.ts

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import noRestrictedHtmlElements from '../rules/no-restricted-html-elements';
4141
import noShorthandStylePropertyOverrides from '../rules/no-shorthand-style-property-overrides';
4242
import noSpacesAroundEqualSignsInAttribute from '../rules/no-spaces-around-equal-signs-in-attribute';
4343
import noStoreAsync from '../rules/no-store-async';
44+
import noSvelteInternal from '../rules/no-svelte-internal';
4445
import noTargetBlank from '../rules/no-target-blank';
4546
import noTrailingSpaces from '../rules/no-trailing-spaces';
4647
import noUnknownStyleDirectiveProperty from '../rules/no-unknown-style-directive-property';
@@ -105,6 +106,7 @@ export const rules = [
105106
noShorthandStylePropertyOverrides,
106107
noSpacesAroundEqualSignsInAttribute,
107108
noStoreAsync,
109+
noSvelteInternal,
108110
noTargetBlank,
109111
noTrailingSpaces,
110112
noUnknownStyleDirectiveProperty,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- message: Importing from svelte/internal is prohibited. This will be removed in Svelte 6.".
2+
line: 2
3+
column: 2
4+
suggestions: null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script>
2+
import { get_current_component } from 'svelte/internal';
3+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script>
2+
import { mount } from 'svelte';
3+
</script>

tests/src/rules/no-svelte-internal.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { RuleTester } from '../../utils/eslint-compat';
2+
import rule from '../../../src/rules/no-svelte-internal';
3+
import { loadTestCases } from '../../utils/utils';
4+
5+
const tester = new RuleTester({
6+
languageOptions: {
7+
ecmaVersion: 2020,
8+
sourceType: 'module'
9+
}
10+
});
11+
12+
tester.run('no-svelte-internal', rule as any, loadTestCases('no-svelte-internal'));

0 commit comments

Comments
 (0)