Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,17 @@ These rules relate to this plugin works:
| Rule ID | Description | |
|:--------|:------------|:---|
| [@ota-meshi/svelte/comment-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/comment-directive/) | support comment-directives in HTML template | :star: |
| [@ota-meshi/svelte/dollar-prefixed-store-uses-vars](https://ota-meshi.github.io/eslint-plugin-svelte/rules/dollar-prefixed-store-uses-vars/) | prevent $-prefixed variables to be marked as unused | :star: |
| [@ota-meshi/svelte/system](https://ota-meshi.github.io/eslint-plugin-svelte/rules/system/) | system rule for working this plugin | :star: |

## Deprecated

- :warning: We're going to remove deprecated rules in the next major release. Please migrate to successor/new rules.
- :innocent: We don't fix bugs which are in deprecated rules since we don't have enough resources.

| Rule ID | Replaced by |
|:--------|:------------|
| [@ota-meshi/svelte/dollar-prefixed-store-uses-vars](https://ota-meshi.github.io/eslint-plugin-svelte/rules/dollar-prefixed-store-uses-vars/) | (no replacement) |

<!--RULES_TABLE_END-->
<!--RULES_SECTION_END-->

Expand Down
10 changes: 9 additions & 1 deletion docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,13 @@ These rules relate to this plugin works:
| Rule ID | Description | |
|:--------|:------------|:---|
| [@ota-meshi/svelte/comment-directive](./rules/comment-directive.md) | support comment-directives in HTML template | :star: |
| [@ota-meshi/svelte/dollar-prefixed-store-uses-vars](./rules/dollar-prefixed-store-uses-vars.md) | prevent $-prefixed variables to be marked as unused | :star: |
| [@ota-meshi/svelte/system](./rules/system.md) | system rule for working this plugin | :star: |

## Deprecated

- :warning: We're going to remove deprecated rules in the next major release. Please migrate to successor/new rules.
- :innocent: We don't fix bugs which are in deprecated rules since we don't have enough resources.

| Rule ID | Replaced by |
|:--------|:------------|
| [@ota-meshi/svelte/dollar-prefixed-store-uses-vars](./rules/dollar-prefixed-store-uses-vars.md) | (no replacement) |
8 changes: 7 additions & 1 deletion docs/rules/dollar-prefixed-store-uses-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ since: "v0.18.0"

> prevent $-prefixed variables to be marked as unused

- :gear: This rule is included in `"plugin:@ota-meshi/svelte/base"` and `"plugin:@ota-meshi/svelte/recommended"`.
- :warning: This rule was **deprecated**.

::: tip

This rule is not needed when using `svelte-eslint-parser` v0.14.0 or later.

:::

ESLint `no-unused-vars` rule does not detect store variables used as $-prefixed.
This rule will find imported store variables that are used as $-prefixed and marks them as used.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"eslint-utils": "^3.0.0",
"postcss": "^8.4.5",
"sourcemap-codec": "^1.4.8",
"svelte-eslint-parser": "^0.13.0"
"svelte-eslint-parser": "^0.14.0"
},
"peerDependencies": {
"eslint": "^7.0.0 || ^8.0.0-0",
Expand Down
1 change: 0 additions & 1 deletion src/configs/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export = {

// @ota-meshi/eslint-plugin-svelte rules
"@ota-meshi/svelte/comment-directive": "error",
"@ota-meshi/svelte/dollar-prefixed-store-uses-vars": "error",
"@ota-meshi/svelte/system": "error",
},
},
Expand Down
1 change: 0 additions & 1 deletion src/configs/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export = {
rules: {
// @ota-meshi/eslint-plugin-svelte rules
"@ota-meshi/svelte/comment-directive": "error",
"@ota-meshi/svelte/dollar-prefixed-store-uses-vars": "error",
"@ota-meshi/svelte/no-at-debug-tags": "warn",
"@ota-meshi/svelte/no-at-html-tags": "error",
"@ota-meshi/svelte/no-dupe-else-if-blocks": "error",
Expand Down
1 change: 1 addition & 0 deletions src/rules/dollar-prefixed-store-uses-vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default createRule("dollar-prefixed-store-uses-vars", {
schema: [],
messages: {},
type: "problem",
deprecated: true, // This rule is not needed when using [email protected] or later.
},
create(context) {
if (!context.parserServices.isSvelte) {
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ export interface RuleMetaData {
url: string
ruleId: string
ruleName: string
replacedBy?: string[]
default?: "error" | "warn"
}
messages: { [messageId: string]: string }
fixable?: "code" | "whitespace"
schema: JSONSchema4 | JSONSchema4[]
deprecated?: boolean
replacedBy?: string[]
type: "problem" | "suggestion" | "layout"
}

Expand All @@ -85,13 +85,13 @@ export interface PartialRuleMetaData {
category: RuleCategory
recommended: boolean | "base"
extensionRule?: string
replacedBy?: string[]
default?: "error" | "warn"
}
messages: { [messageId: string]: string }
fixable?: "code" | "whitespace"
schema: JSONSchema4 | JSONSchema4[]
deprecated?: boolean
replacedBy?: string[]
type: "problem" | "suggestion" | "layout"
}

Expand Down
3 changes: 0 additions & 3 deletions svelte.config.esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ const config = {
pages: "build",
assets: "build",
}),

// hydrate the <div id="svelte"> element in src/app.html
target: "#svelte",
files: {
routes: path.join(dirname, "./docs"),
template: path.join(dirname, "./docs-svelte-kit/src/app.html"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { RuleTester, Linter } from "eslint"
import rule from "../../../src/rules/dollar-prefixed-store-uses-vars"

describe("dollar-prefixed-store-uses-vars", () => {
describe("Integration test for no-unused-vars", () => {
const ruleNoUnusedVars = new Linter().getRules().get("no-unused-vars")!
const tester = new RuleTester({
parser: require.resolve("svelte-eslint-parser"),
Expand All @@ -10,34 +9,28 @@ describe("dollar-prefixed-store-uses-vars", () => {
sourceType: "module",
},
})
const linter = (tester as any).linter
linter.defineRule("dollar-prefixed-store-uses-vars", rule)
tester.run("no-unused-vars", ruleNoUnusedVars, {
valid: [
`
<script>
/* eslint dollar-prefixed-store-uses-vars: 2 */
import { a } from "./stores"
$a = 42
</script>
`,
`
<script>
/* eslint dollar-prefixed-store-uses-vars: 2 */
import { a as b } from "./stores"
$b = 42
</script>
`,
`
<script>
/* eslint dollar-prefixed-store-uses-vars: 2 */
import a from "./stores"
$a = 42
</script>
`,
`
<script>
/* eslint dollar-prefixed-store-uses-vars: 2 */
import * as a from "./stores"
$a = 42
</script>
Expand All @@ -47,7 +40,6 @@ describe("dollar-prefixed-store-uses-vars", () => {
{
code: `
<script>
/* eslint dollar-prefixed-store-uses-vars: 2 */
import { a } from "./stores"
$b = 42
</script>
Expand All @@ -57,7 +49,6 @@ describe("dollar-prefixed-store-uses-vars", () => {
{
code: `
<script>
/* eslint dollar-prefixed-store-uses-vars: 2 */
import { a as b } from "./stores"
$a = 42
</script>
Expand All @@ -67,7 +58,6 @@ describe("dollar-prefixed-store-uses-vars", () => {
{
code: `
<script>
/* eslint dollar-prefixed-store-uses-vars: 2 */
import a from "./stores"
$b = 42
</script>
Expand All @@ -77,7 +67,6 @@ describe("dollar-prefixed-store-uses-vars", () => {
{
code: `
<script>
/* eslint dollar-prefixed-store-uses-vars: 2 */
import * as a from "./stores"
$b = 42
</script>
Expand Down
2 changes: 1 addition & 1 deletion tools/render-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function renderRulesTableContent(
const link = `[${rule.meta.docs.ruleId}](${buildRulePath(
rule.meta.docs.ruleName || "",
)})`
const replacedRules = rule.meta.docs.replacedBy || []
const replacedRules = rule.meta.replacedBy || []
const replacedBy = replacedRules
.map((name) => `[@ota-meshi/svelte/${name}](${buildRulePath(name)}.md)`)
.join(", ")
Expand Down
3 changes: 2 additions & 1 deletion tools/update-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class DocFile {
meta: {
fixable,
deprecated,
docs: { ruleId, description, recommended, replacedBy },
replacedBy,
docs: { ruleId, description, recommended },
},
} = this.rule
const title = `# ${ruleId}\n\n> ${description}`
Expand Down
59 changes: 47 additions & 12 deletions tools/update-rulesets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,65 @@ import path from "path"
import fs from "fs"
import { rules } from "./lib/load-rules"

const content = `
import path from "path"
const base = require.resolve("./base")
const baseExtend =
path.extname(\`\${base}\`) === ".ts" ? "plugin:@ota-meshi/svelte/base" : base
export = {
extends: [baseExtend],
rules: {
const baseContent = `export = {
plugins: ["@ota-meshi/svelte"],
overrides: [
{
files: ["*.svelte"],
parser: require.resolve("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",

// @ota-meshi/eslint-plugin-svelte rules
${rules
.filter((rule) => rule.meta.docs.recommended && !rule.meta.deprecated)
.filter(
(rule) =>
rule.meta.docs.recommended === "base" && !rule.meta.deprecated,
)
.map((rule) => {
const conf = rule.meta.docs.default || "error"
return `"${rule.meta.docs.ruleId}": "${conf}"`
})
.join(",\n")}
.join(",\n ")},
},
},
],
}
`

const baseFilePath = path.resolve(__dirname, "../src/configs/base.ts")

// Update file.
fs.writeFileSync(baseFilePath, baseContent)

const recommendedContent = `import path from "path"
const base = require.resolve("./base")
const baseExtend =
path.extname(\`\${base}\`) === ".ts" ? "plugin:@ota-meshi/svelte/base" : base
export = {
extends: [baseExtend],
rules: {
// @ota-meshi/eslint-plugin-svelte rules
${rules
.filter((rule) => rule.meta.docs.recommended && !rule.meta.deprecated)
.map((rule) => {
const conf = rule.meta.docs.default || "error"
return `"${rule.meta.docs.ruleId}": "${conf}"`
})
.join(",\n ")},
},
}
`

const filePath = path.resolve(__dirname, "../src/configs/recommended.ts")
const recommendedFilePath = path.resolve(
__dirname,
"../src/configs/recommended.ts",
)

// Update file.
fs.writeFileSync(filePath, content)
fs.writeFileSync(recommendedFilePath, recommendedContent)

// Format files.
// const linter = new eslint.CLIEngine({ fix: true })
Expand Down