eslint-plugin-svelte
Advanced tools
Comparing version 3.0.0-next.12 to 3.0.0-next.13
@@ -17,3 +17,3 @@ import './rule-types.js'; | ||
name: "eslint-plugin-svelte"; | ||
version: "3.0.0-next.12"; | ||
version: "3.0.0-next.13"; | ||
}; | ||
@@ -20,0 +20,0 @@ export declare const processors: { |
export declare const name = "eslint-plugin-svelte"; | ||
export declare const version = "3.0.0-next.12"; | ||
export declare const version = "3.0.0-next.13"; |
@@ -5,2 +5,2 @@ // IMPORTANT! | ||
export const name = 'eslint-plugin-svelte'; | ||
export const version = '3.0.0-next.12'; | ||
export const version = '3.0.0-next.13'; |
@@ -101,7 +101,2 @@ import type { Linter } from 'eslint'; | ||
/** | ||
* Recommends not using raw special elements in Svelte versions previous to 5. | ||
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-deprecated-raw-special-elements/ | ||
*/ | ||
'svelte/no-deprecated-raw-special-elements'?: Linter.RuleEntry<[]>; | ||
/** | ||
* disallow DOM manipulating | ||
@@ -193,2 +188,7 @@ * @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dom-manipulating/ | ||
/** | ||
* Checks for invalid raw HTML elements | ||
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-raw-special-elements/ | ||
*/ | ||
'svelte/no-raw-special-elements'?: Linter.RuleEntry<[]>; | ||
/** | ||
* it's not necessary to define functions in reactive statements | ||
@@ -421,3 +421,4 @@ * @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-reactive-functions/ | ||
normal?: ("never" | "always" | "ignore"); | ||
foreign?: ("never" | "always" | "ignore"); | ||
svg?: ("never" | "always" | "ignore"); | ||
math?: ("never" | "always" | "ignore"); | ||
component?: ("never" | "always" | "ignore"); | ||
@@ -424,0 +425,0 @@ svelte?: ("never" | "always" | "ignore"); |
import { createRule } from '../utils/index.js'; | ||
import { getNodeName, isVoidHtmlElement, isForeignElement } from '../utils/ast-utils.js'; | ||
import { getNodeName, isVoidHtmlElement, isSvgElement, isMathMLElement } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
@@ -7,3 +7,4 @@ const TYPE_MESSAGES = { | ||
void: 'HTML void elements', | ||
foreign: 'foreign (SVG or MathML) elements', | ||
svg: 'SVG elements', | ||
math: 'MathML elements', | ||
component: 'Svelte custom components', | ||
@@ -37,5 +38,8 @@ svelte: 'Svelte special elements' | ||
}, | ||
foreign: { | ||
svg: { | ||
enum: ['never', 'always', 'ignore'] | ||
}, | ||
math: { | ||
enum: ['never', 'always', 'ignore'] | ||
}, | ||
component: { | ||
@@ -58,6 +62,8 @@ enum: ['never', 'always', 'ignore'] | ||
create(context) { | ||
// default | ||
let options = { | ||
void: 'always', | ||
normal: 'always', | ||
foreign: 'always', | ||
normal: 'never', | ||
svg: 'always', | ||
math: 'never', | ||
component: 'always', | ||
@@ -68,9 +74,10 @@ svelte: 'always' | ||
switch (option) { | ||
case 'none': | ||
case 'all': | ||
options = { | ||
void: 'never', | ||
normal: 'never', | ||
foreign: 'never', | ||
component: 'never', | ||
svelte: 'never' | ||
void: 'always', | ||
normal: 'always', | ||
svg: 'always', | ||
math: 'always', | ||
component: 'always', | ||
svelte: 'always' | ||
}; | ||
@@ -82,3 +89,4 @@ break; | ||
normal: 'never', | ||
foreign: 'always', | ||
svg: 'always', | ||
math: 'never', | ||
component: 'never', | ||
@@ -88,2 +96,12 @@ svelte: 'always' | ||
break; | ||
case 'none': | ||
options = { | ||
void: 'never', | ||
normal: 'never', | ||
svg: 'never', | ||
math: 'never', | ||
component: 'never', | ||
svelte: 'never' | ||
}; | ||
break; | ||
default: | ||
@@ -112,4 +130,6 @@ if (typeof option !== 'object' || option === null) | ||
return 'void'; | ||
if (isForeignElement(node)) | ||
return 'foreign'; | ||
if (isSvgElement(node)) | ||
return 'svg'; | ||
if (isMathMLElement(node)) | ||
return 'math'; | ||
return 'normal'; | ||
@@ -116,0 +136,0 @@ } |
@@ -108,3 +108,5 @@ import type { ASTNode, RuleContext, SourceCode } from '../types.js'; | ||
export declare function isForeignElement(node: SvAST.SvelteElement): boolean; | ||
export declare function isSvgElement(node: SvAST.SvelteElement): boolean; | ||
export declare function isMathMLElement(node: SvAST.SvelteElement): boolean; | ||
/** Checks whether the given identifier node is used as an expression. */ | ||
export declare function isExpressionIdentifier(node: TSESTree.Identifier): boolean; |
@@ -405,2 +405,8 @@ import * as eslintUtils from '@eslint-community/eslint-utils'; | ||
} | ||
export function isSvgElement(node) { | ||
return svgElements.includes(getNodeName(node)); | ||
} | ||
export function isMathMLElement(node) { | ||
return mathmlElements.includes(getNodeName(node)); | ||
} | ||
/** Checks whether the given identifier node is used as an expression. */ | ||
@@ -407,0 +413,0 @@ export function isExpressionIdentifier(node) { |
@@ -19,3 +19,2 @@ import typescriptEslintNoUnnecessaryCondition from '../rules/@typescript-eslint/no-unnecessary-condition.js'; | ||
import noAtHtmlTags from '../rules/no-at-html-tags.js'; | ||
import noDeprecatedRawSpecialElements from '../rules/no-deprecated-raw-special-elements.js'; | ||
import noDomManipulating from '../rules/no-dom-manipulating.js'; | ||
@@ -38,2 +37,3 @@ import noDupeElseIfBlocks from '../rules/no-dupe-else-if-blocks.js'; | ||
import noObjectInTextMustaches from '../rules/no-object-in-text-mustaches.js'; | ||
import noRawSpecialElements from '../rules/no-raw-special-elements.js'; | ||
import noReactiveFunctions from '../rules/no-reactive-functions.js'; | ||
@@ -91,3 +91,2 @@ import noReactiveLiterals from '../rules/no-reactive-literals.js'; | ||
noAtHtmlTags, | ||
noDeprecatedRawSpecialElements, | ||
noDomManipulating, | ||
@@ -110,2 +109,3 @@ noDupeElseIfBlocks, | ||
noObjectInTextMustaches, | ||
noRawSpecialElements, | ||
noReactiveFunctions, | ||
@@ -112,0 +112,0 @@ noReactiveLiterals, |
@@ -93,3 +93,3 @@ import fs from 'fs'; | ||
} | ||
const major = version.split('.')[0]; | ||
const major = extractMajorVersion(version, false); | ||
if (major === '3' || major === '4') { | ||
@@ -133,3 +133,3 @@ return '3/4'; | ||
} | ||
return version.split('.')[0]; | ||
return extractMajorVersion(version, true); | ||
} | ||
@@ -142,2 +142,15 @@ } | ||
} | ||
function extractMajorVersion(version, recognizePrereleaseVersion) { | ||
if (recognizePrereleaseVersion) { | ||
const match = /^(?:\^|~)?(\d+\.0\.0-next)/.exec(version); | ||
if (match && match[1]) { | ||
return match[1]; | ||
} | ||
} | ||
const match = /^(?:\^|~)?(\d+)\./.exec(version); | ||
if (match && match[1]) { | ||
return match[1]; | ||
} | ||
return null; | ||
} | ||
/** | ||
@@ -144,0 +157,0 @@ * Gets a project root folder path. |
{ | ||
"name": "eslint-plugin-svelte", | ||
"version": "3.0.0-next.12", | ||
"version": "3.0.0-next.13", | ||
"description": "ESLint plugin for Svelte using AST", | ||
@@ -44,3 +44,3 @@ "repository": "git+https://github.com/sveltejs/eslint-plugin-svelte.git", | ||
"semver": "^7.6.3", | ||
"svelte-eslint-parser": "^1.0.0-next.6" | ||
"svelte-eslint-parser": "^1.0.0-next.9" | ||
}, | ||
@@ -47,0 +47,0 @@ "devDependencies": { |
@@ -323,3 +323,2 @@ # Introduction | ||
| [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. | | | ||
| [svelte/no-deprecated-raw-special-elements](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-deprecated-raw-special-elements/) | Recommends not using raw special elements in Svelte versions previous to 5. | :wrench: | | ||
| [svelte/no-dom-manipulating](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dom-manipulating/) | disallow DOM manipulating | | | ||
@@ -334,2 +333,3 @@ | [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: | | ||
| [svelte/no-object-in-text-mustaches](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-object-in-text-mustaches/) | disallow objects in text mustache interpolation | :star: | | ||
| [svelte/no-raw-special-elements](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-raw-special-elements/) | Checks for invalid raw HTML elements | :wrench: | | ||
| [svelte/no-reactive-reassign](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-reactive-reassign/) | disallow reassigning reactive values | | | ||
@@ -336,0 +336,0 @@ | [svelte/no-shorthand-style-property-overrides](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-shorthand-style-property-overrides/) | disallow shorthand style properties that override related longhand properties | :star: | |
710017
16269