-
-
Notifications
You must be signed in to change notification settings - Fork 48
feat: add svelte/no-svelte-internal
rule
#749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
25926f3
dfeat: add svelte/no-svete-internal
baseballyama 299aca1
chore: add changeset
baseballyama 2a3e994
chore: fix lint
baseballyama 8559fa0
fix test
baseballyama 3dd0c66
update
baseballyama 0603998
update docs
baseballyama fca148a
enhance
baseballyama 78887d5
update docs
baseballyama File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 `svelte/no-svelte-internal` rule |
This file contains hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
--- | ||
pageClass: 'rule-details' | ||
sidebarDepth: 0 | ||
title: 'svelte/no-svelte-internal' | ||
description: 'svelte/internal will be removed in Svelte 6.' | ||
--- | ||
|
||
# svelte/no-svelte-internal | ||
|
||
> svelte/internal will be removed in Svelte 6. | ||
|
||
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> **_This rule has not been released yet._** </badge> | ||
|
||
## :book: Rule Details | ||
|
||
This rule reports the use of the deprecated API `svelte/internal` and `svelte/internal/xxx`. `svelte/internal` is deprecated in Svelte 5. And it will be deleted in Svelte 6. These APIs can change in breaking ways at any time without notice. | ||
|
||
<ESLintCodeBlock> | ||
|
||
<!--eslint-skip--> | ||
|
||
```svelte | ||
<script> | ||
/* eslint svelte/no-svelte-internal: "error" */ | ||
// ✓ GOOD | ||
import { mount } from 'svelte'; | ||
|
||
// ✗ BAD | ||
import { get_current_component } from 'svelte/internal'; | ||
import { inspect } from 'svelte/internal/client'; | ||
import('svelte/internal'); | ||
import('svelte/internal/disclose-version'); | ||
|
||
export * from 'svelte/internal'; | ||
export { listen } from 'svelte/internal'; | ||
export * from 'svelte/internal/server'; | ||
</script> | ||
``` | ||
|
||
</ESLintCodeBlock> | ||
|
||
## :wrench: Options | ||
|
||
Nothing. | ||
|
||
## :books: Further Reading | ||
|
||
<!--TODO: update here when relevant statements are added in Svelte 5 documentation --> | ||
|
||
Nothing. | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/src/rules/no-svelte-internal.ts) | ||
- [Test source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/tests/src/rules/no-svelte-internal.ts) |
This file contains hidden or 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 hidden or 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,59 @@ | ||
import { createRule } from '../utils'; | ||
import type { TSESTree } from '@typescript-eslint/types'; | ||
|
||
export default createRule('no-svelte-internal', { | ||
meta: { | ||
docs: { | ||
description: 'svelte/internal will be removed in Svelte 6.', | ||
category: 'Best Practices', | ||
// TODO Switch to recommended in the major version. | ||
// recommended: true, | ||
recommended: false | ||
}, | ||
schema: [], | ||
messages: { | ||
unexpected: 'Using svelte/internal is prohibited. This will be removed in Svelte 6.' | ||
}, | ||
type: 'problem' | ||
}, | ||
create(context) { | ||
function report(node: TSESTree.Node) { | ||
context.report({ | ||
node, | ||
messageId: 'unexpected' | ||
}); | ||
} | ||
|
||
function isSvelteInternal(value: string) { | ||
return value === 'svelte/internal' || value.startsWith('svelte/internal/'); | ||
} | ||
|
||
return { | ||
ImportDeclaration(node) { | ||
if (node.source && isSvelteInternal(node.source.value)) { | ||
report(node); | ||
} | ||
}, | ||
ImportExpression(node) { | ||
if ( | ||
node.source && | ||
node.source.type === 'Literal' && | ||
typeof node.source.value === 'string' && | ||
isSvelteInternal(node.source.value) | ||
) { | ||
report(node); | ||
} | ||
}, | ||
ExportNamedDeclaration(node) { | ||
if (node.source && isSvelteInternal(node.source.value)) { | ||
report(node); | ||
} | ||
}, | ||
ExportAllDeclaration(node) { | ||
if (node.source && isSvelteInternal(node.source.value)) { | ||
report(node); | ||
} | ||
} | ||
}; | ||
} | ||
}); |
This file contains hidden or 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
4 changes: 4 additions & 0 deletions
4
tests/fixtures/rules/no-svelte-internal/invalid/no-svelte-internal01-errors.yaml
This file contains hidden or 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,4 @@ | ||
- message: Using svelte/internal is prohibited. This will be removed in Svelte 6. | ||
line: 3 | ||
column: 2 | ||
suggestions: null |
4 changes: 4 additions & 0 deletions
4
tests/fixtures/rules/no-svelte-internal/invalid/no-svelte-internal01-input.svelte
This file contains hidden or 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,4 @@ | ||
<script> | ||
// eslint-disable-next-line camelcase -- this is a test | ||
import { get_current_component } from 'svelte/internal'; | ||
</script> |
4 changes: 4 additions & 0 deletions
4
tests/fixtures/rules/no-svelte-internal/invalid/no-svelte-internal02-errors.yaml
This file contains hidden or 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,4 @@ | ||
- message: Using svelte/internal is prohibited. This will be removed in Svelte 6. | ||
line: 2 | ||
column: 2 | ||
suggestions: null |
3 changes: 3 additions & 0 deletions
3
tests/fixtures/rules/no-svelte-internal/invalid/no-svelte-internal02-input.svelte
This file contains hidden or 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,3 @@ | ||
<script> | ||
import { inspect } from 'svelte/internal/client'; | ||
</script> |
4 changes: 4 additions & 0 deletions
4
tests/fixtures/rules/no-svelte-internal/invalid/no-svelte-internal03-errors.yaml
This file contains hidden or 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,4 @@ | ||
- message: Using svelte/internal is prohibited. This will be removed in Svelte 6. | ||
line: 2 | ||
column: 2 | ||
suggestions: null |
3 changes: 3 additions & 0 deletions
3
tests/fixtures/rules/no-svelte-internal/invalid/no-svelte-internal03-input.svelte
This file contains hidden or 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,3 @@ | ||
<script> | ||
import * as svelteInternal from 'svelte/internal'; | ||
</script> |
4 changes: 4 additions & 0 deletions
4
tests/fixtures/rules/no-svelte-internal/invalid/no-svelte-internal04-errors.yaml
This file contains hidden or 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,4 @@ | ||
- message: Using svelte/internal is prohibited. This will be removed in Svelte 6. | ||
line: 2 | ||
column: 2 | ||
suggestions: null |
3 changes: 3 additions & 0 deletions
3
tests/fixtures/rules/no-svelte-internal/invalid/no-svelte-internal04-input.svelte
This file contains hidden or 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,3 @@ | ||
<script> | ||
export * from 'svelte/internal'; | ||
</script> |
4 changes: 4 additions & 0 deletions
4
tests/fixtures/rules/no-svelte-internal/invalid/no-svelte-internal05-errors.yaml
This file contains hidden or 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,4 @@ | ||
- message: Using svelte/internal is prohibited. This will be removed in Svelte 6. | ||
line: 2 | ||
column: 2 | ||
suggestions: null |
3 changes: 3 additions & 0 deletions
3
tests/fixtures/rules/no-svelte-internal/invalid/no-svelte-internal05-input.svelte
This file contains hidden or 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,3 @@ | ||
<script> | ||
export * from 'svelte/internal/client'; | ||
</script> |
4 changes: 4 additions & 0 deletions
4
tests/fixtures/rules/no-svelte-internal/invalid/no-svelte-internal06-errors.yaml
This file contains hidden or 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,4 @@ | ||
- message: Using svelte/internal is prohibited. This will be removed in Svelte 6. | ||
line: 2 | ||
column: 2 | ||
suggestions: null |
3 changes: 3 additions & 0 deletions
3
tests/fixtures/rules/no-svelte-internal/invalid/no-svelte-internal06-input.svelte
This file contains hidden or 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,3 @@ | ||
<script> | ||
export { inspect } from 'svelte/internal/client'; | ||
</script> |
4 changes: 4 additions & 0 deletions
4
tests/fixtures/rules/no-svelte-internal/invalid/no-svelte-internal07-errors.yaml
This file contains hidden or 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,4 @@ | ||
- message: Using svelte/internal is prohibited. This will be removed in Svelte 6. | ||
line: 2 | ||
column: 2 | ||
suggestions: null |
3 changes: 3 additions & 0 deletions
3
tests/fixtures/rules/no-svelte-internal/invalid/no-svelte-internal07-input.svelte
This file contains hidden or 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,3 @@ | ||
<script> | ||
import('svelte/internal'); | ||
</script> |
3 changes: 3 additions & 0 deletions
3
tests/fixtures/rules/no-svelte-internal/valid/no-svelte-internal01-input.svelte
This file contains hidden or 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,3 @@ | ||
<script> | ||
import { mount } from 'svelte'; | ||
</script> |
This file contains hidden or 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,12 @@ | ||
import { RuleTester } from '../../utils/eslint-compat'; | ||
import rule from '../../../src/rules/no-svelte-internal'; | ||
import { loadTestCases } from '../../utils/utils'; | ||
|
||
const tester = new RuleTester({ | ||
languageOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: 'module' | ||
} | ||
}); | ||
|
||
tester.run('no-svelte-internal', rule as any, loadTestCases('no-svelte-internal')); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably also check
export * from 'svelte/internal'
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't expect anyone to do that, but I think it would be even better if we also check
import('svelte/internal')
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good! updated: fca148a