Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sveltejs/eslint-plugin-svelte
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.7.2
Choose a base ref
...
head repository: sveltejs/eslint-plugin-svelte
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.8.0
Choose a head ref
  • 4 commits
  • 13 files changed
  • 1 contributor

Commits on Jul 16, 2021

  1. Update doc

    ota-meshi committed Jul 16, 2021
    Copy the full SHA
    5176019 View commit details

Commits on Jul 20, 2021

  1. Add ignoreWarnings option to valid-compile rule (#42)

    * Add ignoreWarnings option to valid-compile rule
    
    * Add test
    ota-meshi authored Jul 20, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fa1cfcc View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1e38bc6 View commit details
  3. 0.8.0

    ota-meshi committed Jul 20, 2021
    Copy the full SHA
    81be5ca View commit details
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -250,7 +250,7 @@ These rules relate to possible syntax or logic errors in Svelte code:
| [@ota-meshi/svelte/no-dupe-else-if-blocks](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-dupe-else-if-blocks.html) | disallow duplicate conditions in `{#if}` / `{:else if}` chains | :star: |
| [@ota-meshi/svelte/no-not-function-handler](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-not-function-handler.html) | disallow use of not function in event handler | :star: |
| [@ota-meshi/svelte/no-object-in-text-mustaches](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-object-in-text-mustaches.html) | disallow objects in text mustache interpolation | :star: |
| [@ota-meshi/svelte/valid-compile](https://ota-meshi.github.io/eslint-plugin-svelte/rules/valid-compile.html) | disallow warnings when compiling. | |
| [@ota-meshi/svelte/valid-compile](https://ota-meshi.github.io/eslint-plugin-svelte/rules/valid-compile.html) | disallow warnings when compiling. | :star: |

## Security Vulnerability

@@ -285,22 +285,22 @@ These rules relate to style guidelines, and are therefore quite subjective:
| [@ota-meshi/svelte/shorthand-attribute](https://ota-meshi.github.io/eslint-plugin-svelte/rules/shorthand-attribute.html) | enforce use of shorthand syntax in attribute | :wrench: |
| [@ota-meshi/svelte/spaced-html-comment](https://ota-meshi.github.io/eslint-plugin-svelte/rules/spaced-html-comment.html) | enforce consistent spacing after the `<!--` and before the `-->` in a HTML comment | :wrench: |

## System
## Extension Rules

These rules relate to this plugin works:
These rules extend the rules provided by ESLint itself to work well in Svelte:

| Rule ID | Description | |
|:--------|:------------|:---|
| [@ota-meshi/svelte/comment-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/comment-directive.html) | support comment-directives in HTML template | :star: |
| [@ota-meshi/svelte/system](https://ota-meshi.github.io/eslint-plugin-svelte/rules/system.html) | system rule for working this plugin | :star: |
| [@ota-meshi/svelte/no-inner-declarations](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-inner-declarations.html) | disallow variable or `function` declarations in nested blocks | :star: |

## Extension Rules
## System

These rules extend the rules provided by ESLint itself to work well in Svelte:
These rules relate to this plugin works:

| Rule ID | Description | |
|:--------|:------------|:---|
| [@ota-meshi/svelte/no-inner-declarations](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-inner-declarations.html) | disallow variable or `function` declarations in nested blocks | :star: |
| [@ota-meshi/svelte/comment-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/comment-directive.html) | support comment-directives in HTML template | :star: |
| [@ota-meshi/svelte/system](https://ota-meshi.github.io/eslint-plugin-svelte/rules/system.html) | system rule for working this plugin | :star: |

<!--RULES_TABLE_END-->
<!--RULES_SECTION_END-->
10 changes: 4 additions & 6 deletions docs/.vuepress/components/rules/index.js
Original file line number Diff line number Diff line change
@@ -24,8 +24,8 @@ const CATEGORY_INDEX = {
"Security Vulnerability": 2,
"Best Practices": 3,
"Stylistic Issues": 4,
System: 5,
"Extension Rules": 5.5,
"Extension Rules": 5,
System: 5.5,
"eslint-core-rules@Possible Errors": 6,
"eslint-core-rules@Best Practices": 7,
"eslint-core-rules@Strict Mode": 8,
@@ -39,8 +39,8 @@ const CATEGORY_CLASSES = {
"Security Vulnerability": "eslint-plugin-svelte__category",
"Best Practices": "eslint-plugin-svelte__category",
"Stylistic Issues": "eslint-plugin-svelte__category",
System: "eslint-plugin-svelte__category",
"Extension Rules": "eslint-plugin-svelte__category",
System: "eslint-plugin-svelte__category",
}

const allRules = []
@@ -51,9 +51,7 @@ for (const k of Object.keys(plugin.rules)) {
continue
}

const category = rule.meta.docs.extensionRule
? "Extension Rules"
: rule.meta.docs.category
const category = rule.meta.docs.category

allRules.push({
classes: "eslint-plugin-svelte__rule",
18 changes: 2 additions & 16 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
@@ -2,15 +2,14 @@ const path = require("path")
// eslint-disable-next-line node/no-missing-require, node/no-unpublished-require -- no build
const { rules } = require("../../lib/utils/rules")

const svelteRules = rules.filter(
(rule) => !rule.meta.docs.extensionRule && !rule.meta.deprecated,
)
const svelteRules = rules.filter((rule) => !rule.meta.deprecated)

const categories = [
"Possible Errors",
"Security Vulnerability",
"Best Practices",
"Stylistic Issues",
"Extension Rules",
"System",
]
svelteRules.forEach((rule) => {
@@ -25,10 +24,6 @@ const categoryRules = categories.map((cat) => {
}
})

const extensionRules = rules.filter(
(rule) => rule.meta.docs.extensionRule && !rule.meta.deprecated,
)

function ruleToLink({
meta: {
docs: { ruleId, ruleName },
@@ -84,15 +79,6 @@ module.exports = {
children: cat.rules.map(ruleToLink),
}
}),
...(extensionRules.length
? [
{
title: "Extension Rules",
collapsable: false,
children: extensionRules.map(ruleToLink),
},
]
: []),
// Rules in no category.
...(rules.some((rule) => rule.meta.deprecated)
? [
16 changes: 8 additions & 8 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ These rules relate to possible syntax or logic errors in Svelte code:
| [@ota-meshi/svelte/no-dupe-else-if-blocks](./no-dupe-else-if-blocks.md) | disallow duplicate conditions in `{#if}` / `{:else if}` chains | :star: |
| [@ota-meshi/svelte/no-not-function-handler](./no-not-function-handler.md) | disallow use of not function in event handler | :star: |
| [@ota-meshi/svelte/no-object-in-text-mustaches](./no-object-in-text-mustaches.md) | disallow objects in text mustache interpolation | :star: |
| [@ota-meshi/svelte/valid-compile](./valid-compile.md) | disallow warnings when compiling. | |
| [@ota-meshi/svelte/valid-compile](./valid-compile.md) | disallow warnings when compiling. | :star: |

## Security Vulnerability

@@ -53,19 +53,19 @@ These rules relate to style guidelines, and are therefore quite subjective:
| [@ota-meshi/svelte/shorthand-attribute](./shorthand-attribute.md) | enforce use of shorthand syntax in attribute | :wrench: |
| [@ota-meshi/svelte/spaced-html-comment](./spaced-html-comment.md) | enforce consistent spacing after the `<!--` and before the `-->` in a HTML comment | :wrench: |

## System
## Extension Rules

These rules relate to this plugin works:
These rules extend the rules provided by ESLint itself to work well in Svelte:

| Rule ID | Description | |
|:--------|:------------|:---|
| [@ota-meshi/svelte/comment-directive](./comment-directive.md) | support comment-directives in HTML template | :star: |
| [@ota-meshi/svelte/system](./system.md) | system rule for working this plugin | :star: |
| [@ota-meshi/svelte/no-inner-declarations](./no-inner-declarations.md) | disallow variable or `function` declarations in nested blocks | :star: |

## Extension Rules
## System

These rules extend the rules provided by ESLint itself to work well in Svelte:
These rules relate to this plugin works:

| Rule ID | Description | |
|:--------|:------------|:---|
| [@ota-meshi/svelte/no-inner-declarations](./no-inner-declarations.md) | disallow variable or `function` declarations in nested blocks | :star: |
| [@ota-meshi/svelte/comment-directive](./comment-directive.md) | support comment-directives in HTML template | :star: |
| [@ota-meshi/svelte/system](./system.md) | system rule for working this plugin | :star: |
31 changes: 30 additions & 1 deletion docs/rules/valid-compile.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ since: "v0.7.0"

> disallow warnings when compiling.
- :gear: This rule is included in `"plugin:@ota-meshi/svelte/recommended"`.

## :book: Rule Details

This rule uses Svelte compiler to check the source code.
@@ -37,7 +39,34 @@ Note that we exclude reports for some checks, such as `missing-declaration`, whi

## :wrench: Options

Nothing.
```json
{
"@ota-meshi/svelte/valid-compile": [
"error",
{
"ignoreWarnings": false
}
]
}
```

- `ignoreWarnings` ... If set to `true`, ignores any warnings other than fatal errors reported by the svelte compiler.

<eslint-code-block>

<!--eslint-skip-->

```svelte
<script>
/* eslint @ota-meshi/svelte/valid-compile: ["error", { ignoreWarnings: true }] */
let src = "tutorial/image.gif"
</script>
<!-- Ignore -->
<img {src} />
```

</eslint-code-block>

## :rocket: Version

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ota-meshi/eslint-plugin-svelte",
"version": "0.7.2",
"version": "0.8.0",
"publishConfig": {
"access": "public"
},
1 change: 1 addition & 0 deletions src/configs/recommended.ts
Original file line number Diff line number Diff line change
@@ -14,5 +14,6 @@ export = {
"@ota-meshi/svelte/no-not-function-handler": "error",
"@ota-meshi/svelte/no-object-in-text-mustaches": "error",
"@ota-meshi/svelte/system": "error",
"@ota-meshi/svelte/valid-compile": "error",
},
}
2 changes: 1 addition & 1 deletion src/rules/no-inner-declarations.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ export default createRule("no-inner-declarations", {
docs: {
description:
"disallow variable or `function` declarations in nested blocks",
category: "Possible Errors",
category: "Extension Rules",
recommended: true,
extensionRule: "no-inner-declarations",
},
56 changes: 34 additions & 22 deletions src/rules/valid-compile.ts
Original file line number Diff line number Diff line change
@@ -65,13 +65,22 @@ export default createRule("valid-compile", {
docs: {
description: "disallow warnings when compiling.",
category: "Possible Errors",
recommended: false,
recommended: true,
},
schema: [],
schema: [
{
type: "object",
properties: {
ignoreWarnings: { type: "boolean" },
},
additionalProperties: false,
},
],
messages: {},
type: "problem",
},
create(context) {
const ignoreWarnings = Boolean(context.options[0]?.ignoreWarnings)
const sourceCode = context.getSourceCode()
const text = sourceCode.text

@@ -320,29 +329,32 @@ export default createRule("valid-compile", {
report(getWarnings(code), (warn) => remapContext.remapLocs(warn))
},
}

/**
* Get compile warnings
*/
function getWarnings(code: string): Warning[] {
try {
const result = compiler.compile(code, { generate: false })

if (ignoreWarnings) {
return []
}
return result.warnings
} catch (e) {
// console.log(code)
return [
{
message: e.message,
start: e.start,
end: e.end,
},
]
}
}
},
})

/**
* Get compile warnings
*/
function getWarnings(code: string): Warning[] {
try {
const result = compiler.compile(code, { generate: false })

return result.warnings
} catch (e) {
// console.log(code)
return [
{
message: e.message,
start: e.start,
end: e.end,
},
]
}
}

/**
* Checks if the given visitorKeys are the equals.
*/
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@ export type RuleCategory =
| "Security Vulnerability"
| "Best Practices"
| "Stylistic Issues"
| "Extension Rules"
| "System"

export interface RuleMetaData {
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"options": [{ "ignoreWarnings": true }]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
let src = "tutorial/image.gif"
</script>

<img {src} />
19 changes: 4 additions & 15 deletions tools/render-rules.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ const categories = [
"Security Vulnerability",
"Best Practices",
"Stylistic Issues",
"Extension Rules",
"System",
] as const

@@ -18,14 +19,13 @@ const descriptions: Record<typeof categories[number], string> = {
"These rules relate to better ways of doing things to help you avoid problems:",
"Stylistic Issues":
"These rules relate to style guidelines, and are therefore quite subjective:",
"Extension Rules":
"These rules extend the rules provided by ESLint itself to work well in Svelte:",
System: "These rules relate to this plugin works:",
}

const activeRules = rules.filter((rule) => !rule.meta.deprecated)
const svelteRules = activeRules.filter((rule) => !rule.meta.docs.extensionRule)
const extensionRules = activeRules.filter(
(rule) => rule.meta.docs.extensionRule,
)
const svelteRules = activeRules
const deprecatedRules = rules.filter((rule) => rule.meta.deprecated)

activeRules.forEach((rule) => {
@@ -87,17 +87,6 @@ ${cat.rules.map(toRuleRow).join("\n")}
`
})
.join("")
if (extensionRules.length >= 1) {
rulesTableContent += `
## Extension Rules
These rules extend the rules provided by ESLint itself to work well in Svelte:
| Rule ID | Description | |
|:--------|:------------|:---|
${extensionRules.map(toRuleRow).join("\n")}
`
}

// -----------------------------------------------------------------------------
if (deprecatedRules.length >= 1) {