eslint-plugin-svelte
Advanced tools
@@ -17,3 +17,3 @@ import './rule-types.js'; | ||
name: "eslint-plugin-svelte"; | ||
version: "3.4.0"; | ||
version: "3.4.1"; | ||
}; | ||
@@ -20,0 +20,0 @@ export declare const processors: { |
export declare const name = "eslint-plugin-svelte"; | ||
export declare const version = "3.4.0"; | ||
export declare const version = "3.4.1"; |
@@ -5,2 +5,2 @@ // IMPORTANT! | ||
export const name = 'eslint-plugin-svelte'; | ||
export const version = '3.4.0'; | ||
export const version = '3.4.1'; |
import { createRule } from '../../utils/index.js'; | ||
import { isFalsyType, getConstrainedTypeAtLocation, isTruthyLiteral, isPossiblyFalsyType, isNullishType, isBooleanLiteralType, getTypeScriptTools, isAnyType, isUnknownType, isNeverType, getCallSignaturesOfType, isNullableType, getTypeOfPropertyOfType, getTypeName, isTupleType } from '../../utils/ts-utils/index.js'; | ||
import { getSourceCode } from '../../utils/compat.js'; | ||
/** | ||
@@ -115,3 +114,3 @@ * Returns all types of a union type or an array containing `type` itself if it's no union type. | ||
const checker = service.program.getTypeChecker(); | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const compilerOptions = service.program.getCompilerOptions(); | ||
@@ -118,0 +117,0 @@ const isStrictNullChecks = compilerOptions.strict |
import { createRule } from '../utils/index.js'; | ||
import { findAttribute, getLangValue } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('block-lang', { | ||
@@ -58,3 +57,3 @@ meta: { | ||
create(context) { | ||
if (!getSourceCode(context).parserServices.isSvelte) { | ||
if (!context.sourceCode.parserServices.isSvelte) { | ||
return {}; | ||
@@ -86,3 +85,3 @@ } | ||
message: `The <script> block should be present and its lang attribute should be ${prettyPrintLangs(allowedScriptLangs)}.`, | ||
suggest: buildAddLangSuggestions(allowedScriptLangs, 'script', getSourceCode(context)) | ||
suggest: buildAddLangSuggestions(allowedScriptLangs, 'script', context.sourceCode) | ||
}); | ||
@@ -100,3 +99,3 @@ } | ||
if (styleNodes.length === 0 && enforceStylePresent) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
context.report({ | ||
@@ -103,0 +102,0 @@ loc: { line: 1, column: 1 }, |
import { getShared } from '../shared/index.js'; | ||
import { createRule } from '../utils/index.js'; | ||
import { getFilename, getSourceCode } from '../utils/compat.js'; | ||
// ----------------------------------------------------------------------------- | ||
@@ -46,3 +45,3 @@ // Helpers | ||
create(context) { | ||
const shared = getShared(getFilename(context)); | ||
const shared = getShared(context.filename); | ||
if (!shared) | ||
@@ -56,3 +55,3 @@ return {}; | ||
}); | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
/** | ||
@@ -59,0 +58,0 @@ * Parse a given comment. |
import { findClassesInAttribute } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
import { createRule } from '../utils/index.js'; | ||
@@ -42,3 +41,3 @@ export default createRule('consistent-selector-style', { | ||
create(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
if (!sourceCode.parserServices.isSvelte || | ||
@@ -45,0 +44,0 @@ sourceCode.parserServices.getStyleSelectorAST === undefined || |
import { createRule } from '../utils/index.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('first-attribute-linebreak', { | ||
@@ -31,3 +30,3 @@ meta: { | ||
const singleline = context.options[0]?.singleline || 'beside'; | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
/** | ||
@@ -34,0 +33,0 @@ * Report attribute |
import { createRule } from '../utils/index.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
function getPhrase(lineBreaks) { | ||
@@ -83,3 +82,3 @@ switch (lineBreaks) { | ||
options.multiline ?? (options.multiline = 'always'); | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
return { | ||
@@ -86,0 +85,0 @@ 'SvelteStartTag, SvelteEndTag'(node) { |
@@ -41,3 +41,3 @@ import { createRule } from '../utils/index.js'; | ||
}; | ||
const src = ctx.getSourceCode(); | ||
const src = ctx.sourceCode; | ||
/** | ||
@@ -44,0 +44,0 @@ * Returns true if string contains newline characters |
import { createRule } from '../utils/index.js'; | ||
import { getMustacheTokens } from '../utils/ast-utils.js'; | ||
import { getAttributeValueQuoteAndRange } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
const QUOTE_CHARS = { | ||
@@ -48,3 +47,3 @@ double: '"', | ||
create(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const preferQuote = context.options[0]?.prefer ?? 'double'; | ||
@@ -51,0 +50,0 @@ const dynamicQuote = context.options[0]?.dynamic?.quoted ? preferQuote : 'unquoted'; |
import { createRule } from '../utils/index.js'; | ||
import { getNodeName, isVoidHtmlElement, isSvgElement, isMathMLElement } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
const TYPE_MESSAGES = { | ||
@@ -152,3 +151,3 @@ normal: 'HTML elements', | ||
loc: { | ||
start: getSourceCode(context).getLocFromIndex(node.startTag.range[1] - (node.startTag.selfClosing ? 2 : 1)), | ||
start: context.sourceCode.getLocFromIndex(node.startTag.range[1] - (node.startTag.selfClosing ? 2 : 1)), | ||
end: node.loc.end | ||
@@ -155,0 +154,0 @@ }, |
@@ -7,3 +7,2 @@ import * as SV from './svelte.js'; | ||
import { OffsetContext } from './offset-context.js'; | ||
import { getFilename, getSourceCode } from '../../utils/compat.js'; | ||
/** | ||
@@ -58,6 +57,6 @@ * Normalize options. | ||
export function defineVisitor(context, defaultOptions) { | ||
if (!getFilename(context).endsWith('.svelte')) | ||
if (!context.filename.endsWith('.svelte')) | ||
return {}; | ||
const options = parseOptions(context.options[0] || {}, defaultOptions); | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const offsets = new OffsetContext({ sourceCode, options }); | ||
@@ -64,0 +63,0 @@ /** |
@@ -5,3 +5,2 @@ import { ReferenceTracker } from '@eslint-community/eslint-utils'; | ||
import { traverseNodes } from 'svelte-eslint-parser'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
/** | ||
@@ -11,3 +10,3 @@ * Get usage of `tick` | ||
function extractTickReferences(context) { | ||
const referenceTracker = new ReferenceTracker(getSourceCode(context).scopeManager.globalScope); | ||
const referenceTracker = new ReferenceTracker(context.sourceCode.scopeManager.globalScope); | ||
const a = referenceTracker.iterateEsmReferences({ | ||
@@ -32,3 +31,3 @@ svelte: { | ||
function extractTaskReferences(context) { | ||
const referenceTracker = new ReferenceTracker(getSourceCode(context).scopeManager.globalScope); | ||
const referenceTracker = new ReferenceTracker(context.sourceCode.scopeManager.globalScope); | ||
const a = referenceTracker.iterateGlobalReferences({ | ||
@@ -112,3 +111,3 @@ setTimeout: { [ReferenceTracker.CALL]: true }, | ||
function getReactiveVariableReferences(context) { | ||
const scopeManager = getSourceCode(context).scopeManager; | ||
const scopeManager = context.sourceCode.scopeManager; | ||
// Find the top-level (module or global) scope. | ||
@@ -115,0 +114,0 @@ // Any variable defined at the top-level (module scope or global scope) can be made reactive. |
import { createRule } from '../utils/index.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
/** | ||
@@ -57,3 +56,3 @@ * Check whether the component is declared in a single line or not. | ||
const singlelineMaximum = context.options[0]?.singleline ?? 1; | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
/** | ||
@@ -60,0 +59,0 @@ * Report attributes |
import { isClosingBraceToken, isOpeningBraceToken } from '@eslint-community/eslint-utils'; | ||
import { createRule } from '../utils/index.js'; | ||
import { getMustacheTokens } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
const VALUE_SCHEMA = { enum: ['never', 'always'] }; | ||
@@ -60,3 +59,3 @@ /** | ||
const options = parseOptions(context.options[0]); | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
/** Verify */ | ||
@@ -63,0 +62,0 @@ function verifyBraces(openingBrace, closingBrace, openingOption, closingOption, hasExpression) { |
import { createRule } from '../utils/index.js'; | ||
import { equalTokens } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
/** | ||
@@ -61,3 +60,3 @@ * Splits the given node by the given logical operator. | ||
create(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
/** | ||
@@ -64,0 +63,0 @@ * Determines whether the two given nodes are considered to be equal. In particular, given that the nodes |
import { createRule } from '../utils/index.js'; | ||
import { equalTokens } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('no-dupe-on-directives', { | ||
@@ -18,3 +17,3 @@ meta: { | ||
create(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const directiveDataMap = new Map(); | ||
@@ -21,0 +20,0 @@ return { |
import { createRule } from '../utils/index.js'; | ||
import { equalTokens, getAttributeKeyText } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('no-dupe-use-directives', { | ||
@@ -18,3 +17,3 @@ meta: { | ||
create(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const directiveDataMap = new Map(); | ||
@@ -21,0 +20,0 @@ return { |
import { createRule } from '../utils/index.js'; | ||
import { findVariable, getAttributeValueQuoteAndRange, getStringIfConstant } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('no-dynamic-slot-name', { | ||
@@ -24,3 +23,3 @@ meta: { | ||
create(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
return { | ||
@@ -27,0 +26,0 @@ "SvelteElement[name.name='slot'] > SvelteStartTag.startTag > SvelteAttribute[key.name='name']"(node) { |
import { createRule } from '../utils/index.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('no-extra-reactive-curlies', { | ||
@@ -23,3 +22,3 @@ meta: { | ||
[`SvelteReactiveStatement > BlockStatement[body.length=1]`]: (node) => { | ||
const source = getSourceCode(context); | ||
const source = context.sourceCode; | ||
return context.report({ | ||
@@ -26,0 +25,0 @@ node, |
import { createRule } from '../utils/index.js'; | ||
import { ReferenceTracker } from '@eslint-community/eslint-utils'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
import { findVariable } from '../utils/ast-utils.js'; | ||
@@ -23,3 +22,3 @@ export default createRule('no-goto-without-base', { | ||
Program() { | ||
const referenceTracker = new ReferenceTracker(getSourceCode(context).scopeManager.globalScope); | ||
const referenceTracker = new ReferenceTracker(context.sourceCode.scopeManager.globalScope); | ||
const basePathNames = extractBasePathReferences(referenceTracker, context); | ||
@@ -26,0 +25,0 @@ for (const gotoCall of extractGotoReferences(referenceTracker)) { |
import { createRule } from '../utils/index.js'; | ||
import { findVariable, iterateIdentifiers } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('no-immutable-reactive-statements', { | ||
@@ -18,3 +17,3 @@ meta: { | ||
create(context) { | ||
const scopeManager = getSourceCode(context).scopeManager; | ||
const scopeManager = context.sourceCode.scopeManager; | ||
const globalScope = scopeManager.globalScope; | ||
@@ -21,0 +20,0 @@ const toplevelScope = globalScope?.childScopes.find((scope) => scope.type === 'module') || globalScope; |
import { createRule } from '../utils/index.js'; | ||
import { ReferenceTracker } from '@eslint-community/eslint-utils'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
import { findVariable } from '../utils/ast-utils.js'; | ||
@@ -44,3 +43,3 @@ export default createRule('no-navigation-without-base', { | ||
Program() { | ||
const referenceTracker = new ReferenceTracker(getSourceCode(context).scopeManager.globalScope); | ||
const referenceTracker = new ReferenceTracker(context.sourceCode.scopeManager.globalScope); | ||
basePathNames = extractBasePathReferences(referenceTracker, context); | ||
@@ -47,0 +46,0 @@ const { goto: gotoCalls, pushState: pushStateCalls, replaceState: replaceStateCalls } = extractFunctionCallReferences(referenceTracker); |
import { createRule } from '../utils/index.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('no-reactive-functions', { | ||
@@ -36,3 +35,3 @@ meta: { | ||
} | ||
const source = getSourceCode(context); | ||
const source = context.sourceCode; | ||
return context.report({ | ||
@@ -39,0 +38,0 @@ node: parent, |
import { createRule } from '../utils/index.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('no-reactive-literals', { | ||
@@ -43,3 +42,3 @@ meta: { | ||
} | ||
const source = getSourceCode(context); | ||
const source = context.sourceCode; | ||
return context.report({ | ||
@@ -46,0 +45,0 @@ node: parent, |
import { createRule } from '../utils/index.js'; | ||
import { getPropertyName } from '@eslint-community/eslint-utils'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('no-reactive-reassign', { | ||
@@ -39,3 +38,3 @@ meta: { | ||
const props = context.options[0]?.props !== false; // default true | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const scopeManager = sourceCode.scopeManager; | ||
@@ -42,0 +41,0 @@ const globalScope = scopeManager.globalScope; |
@@ -18,3 +18,3 @@ import { createRule } from '../utils/index.js'; | ||
create(ctx) { | ||
const source = ctx.getSourceCode(); | ||
const source = ctx.sourceCode; | ||
/** | ||
@@ -21,0 +21,0 @@ * Returns source text between attribute key and value, and range of that source |
import { createRule } from '../utils/index.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('no-trailing-spaces', { | ||
@@ -32,3 +31,3 @@ meta: { | ||
const ignoreComments = options?.ignoreComments || false; | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const ignoreLineNumbers = new Set(); | ||
@@ -35,0 +34,0 @@ if (ignoreComments) { |
import { createRule } from '../utils/index.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
import { ReferenceTracker } from '@eslint-community/eslint-utils'; | ||
@@ -54,3 +53,3 @@ const REACTIVE_CLASSES = [ | ||
const allowReassign = options.allowReassign ?? false; | ||
const referenceTracker = new ReferenceTracker(getSourceCode(context).scopeManager.globalScope); | ||
const referenceTracker = new ReferenceTracker(context.sourceCode.scopeManager.globalScope); | ||
const traceMap = {}; | ||
@@ -77,3 +76,3 @@ for (const reactiveClass of REACTIVE_CLASSES) { | ||
function isReassigned(identifier) { | ||
const variable = getSourceCode(context).scopeManager.getDeclaredVariables(identifier.parent)[0]; | ||
const variable = context.sourceCode.scopeManager.getDeclaredVariables(identifier.parent)[0]; | ||
return variable.references.some((ref) => { | ||
@@ -97,3 +96,3 @@ return ref.isWrite() && ref.identifier !== identifier; | ||
fix(fixer) { | ||
return fixer.replaceText(stateNode, getSourceCode(context).getText(targetNode)); | ||
return fixer.replaceText(stateNode, context.sourceCode.getText(targetNode)); | ||
} | ||
@@ -100,0 +99,0 @@ } |
import { createRule } from '../utils/index.js'; | ||
import { findClassesInAttribute } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('no-unused-class-name', { | ||
@@ -29,3 +28,3 @@ meta: { | ||
create(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
if (!sourceCode.parserServices.isSvelte) { | ||
@@ -32,0 +31,0 @@ return {}; |
@@ -5,3 +5,2 @@ import { createRule } from '../utils/index.js'; | ||
import { toRegExp } from '../utils/regexp.js'; | ||
import { getFilename } from '../utils/compat.js'; | ||
let isRemovedWarningShown = false; | ||
@@ -55,3 +54,3 @@ export default createRule('no-unused-props', { | ||
create(context) { | ||
const fileName = getFilename(context); | ||
const fileName = context.filename; | ||
const tools = getTypeScriptTools(context); | ||
@@ -58,0 +57,0 @@ if (!tools) { |
import { getSvelteCompileWarnings } from '../shared/svelte-compile-warns/index.js'; | ||
import { createRule } from '../utils/index.js'; | ||
import { getSvelteIgnoreItems } from '../shared/svelte-compile-warns/ignore-comment.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('no-unused-svelte-ignore', { | ||
@@ -20,3 +19,3 @@ meta: { | ||
create(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
if (!sourceCode.parserServices.isSvelte) { | ||
@@ -23,0 +22,0 @@ return {}; |
import { createRule } from '../utils/index.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
/** | ||
@@ -44,3 +43,3 @@ * Strip quotes string | ||
const ignoreStringEscape = Boolean(opts.ignoreStringEscape); | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
/** | ||
@@ -47,0 +46,0 @@ * Report if the value expression is string literals |
import { createRule } from '../utils/index.js'; | ||
import { getStringIfConstant, isHTMLElementLike, needParentheses } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('prefer-class-directive', { | ||
@@ -28,3 +27,3 @@ meta: { | ||
create(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const preferEmpty = context.options[0]?.prefer !== 'always'; | ||
@@ -31,0 +30,0 @@ /** |
@@ -5,3 +5,2 @@ import { getPropertyName } from '@eslint-community/eslint-utils'; | ||
import { findAttribute, isExpressionIdentifier, findVariable } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('prefer-destructured-store-props', { | ||
@@ -79,3 +78,3 @@ meta: { | ||
function hasTopLevelVariable(name) { | ||
const scopeManager = getSourceCode(context).scopeManager; | ||
const scopeManager = context.sourceCode.scopeManager; | ||
if (scopeManager.globalScope?.set.has(name)) { | ||
@@ -193,3 +192,3 @@ return true; | ||
? node.property.name | ||
: getSourceCode(context).getText(node.property).replace(/\s+/g, ' ') | ||
: context.sourceCode.getText(node.property).replace(/\s+/g, ' ') | ||
}, | ||
@@ -196,0 +195,0 @@ suggest |
import { createRule } from '../utils/index.js'; | ||
import { parseStyleAttributeValue } from '../utils/css-utils/index.js'; | ||
import { isHTMLElementLike } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
/** Checks wether the given node is string literal or not */ | ||
@@ -25,3 +24,3 @@ function isStringLiteral(node) { | ||
create(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
/** | ||
@@ -28,0 +27,0 @@ * Process for `style=" ... "` |
import { ReferenceTracker } from '@eslint-community/eslint-utils'; | ||
import { getTypeScriptTools } from '../../utils/ts-utils/index.js'; | ||
import { findVariable, getParent } from '../../utils/ast-utils.js'; | ||
import { getSourceCode } from '../../utils/compat.js'; | ||
/** Extract 'svelte/store' references */ | ||
export function* extractStoreReferences(context, storeNames = ['writable', 'readable', 'derived']) { | ||
const referenceTracker = new ReferenceTracker(getSourceCode(context).scopeManager.globalScope); | ||
const referenceTracker = new ReferenceTracker(context.sourceCode.scopeManager.globalScope); | ||
for (const { node, path } of referenceTracker.iterateEsmReferences({ | ||
@@ -9,0 +8,0 @@ 'svelte/store': { |
import { ReferenceTracker } from '@eslint-community/eslint-utils'; | ||
import { createRule } from '../utils/index.js'; | ||
import { getLangValue } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('require-event-dispatcher-types', { | ||
@@ -36,3 +35,3 @@ meta: { | ||
} | ||
const referenceTracker = new ReferenceTracker(getSourceCode(context).scopeManager.globalScope); | ||
const referenceTracker = new ReferenceTracker(context.sourceCode.scopeManager.globalScope); | ||
for (const { node: n } of referenceTracker.iterateEsmReferences({ | ||
@@ -39,0 +38,0 @@ svelte: { |
import { findVariableForReplacement } from '../utils/ast-utils.js'; | ||
import { createRule } from '../utils/index.js'; | ||
import { extractStoreReferences } from './reference-helpers/svelte-store.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('require-store-callbacks-use-set-param', { | ||
@@ -49,3 +48,3 @@ meta: { | ||
else { | ||
const token = getSourceCode(context).getTokenBefore(fn.body, { | ||
const token = context.sourceCode.getTokenBefore(fn.body, { | ||
filter: (token) => token.type === 'Punctuator' && token.value === '(', | ||
@@ -52,0 +51,0 @@ includeComments: false |
import { createRule } from '../utils/index.js'; | ||
import { createStoreChecker } from './reference-helpers/svelte-store.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('require-store-reactive-access', { | ||
@@ -19,3 +18,3 @@ meta: { | ||
create(context) { | ||
if (!getSourceCode(context).parserServices.isSvelte) { | ||
if (!context.sourceCode.parserServices.isSvelte) { | ||
return {}; | ||
@@ -22,0 +21,0 @@ } |
import { createRule } from '../utils/index.js'; | ||
import { getAttributeValueQuoteAndRange } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('shorthand-attribute', { | ||
@@ -29,3 +28,3 @@ meta: { | ||
create(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const always = context.options[0]?.prefer !== 'never'; | ||
@@ -32,0 +31,0 @@ return always |
import { createRule } from '../utils/index.js'; | ||
import { getAttributeValueQuoteAndRange } from '../utils/ast-utils.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
export default createRule('shorthand-directive', { | ||
@@ -29,3 +28,3 @@ meta: { | ||
create(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const always = context.options[0]?.prefer !== 'never'; | ||
@@ -32,0 +31,0 @@ /** Report for always */ |
import { createRule } from '../utils/index.js'; | ||
import { getAttributeKeyText } from '../utils/ast-utils.js'; | ||
import { toRegExp } from '../utils/regexp.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
const DEFAULT_ORDER = [ | ||
@@ -222,3 +221,3 @@ // `this` property. | ||
const moveNodes = [node, ...previousNodes]; | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
return moveNodes.map((moveNode, index) => { | ||
@@ -225,0 +224,0 @@ const text = sourceCode.getText(moveNode); |
import { getShared } from '../shared/index.js'; | ||
import { createRule } from '../utils/index.js'; | ||
import { getFilename } from '../utils/compat.js'; | ||
import { isRegExp, toRegExp } from '../utils/regexp.js'; | ||
@@ -17,3 +16,3 @@ export default createRule('system', { | ||
create(context) { | ||
const shared = getShared(getFilename(context)); | ||
const shared = getShared(context.filename); | ||
if (!shared) | ||
@@ -20,0 +19,0 @@ return {}; |
import { createRule } from '../utils/index.js'; | ||
import { getSvelteCompileWarnings } from '../shared/svelte-compile-warns/index.js'; | ||
import { getSourceCode } from '../utils/compat.js'; | ||
const ignores = ['missing-declaration']; | ||
@@ -36,3 +35,3 @@ const unusedSelectorWarnings = ['css_unused_selector', 'css-unused-selector']; | ||
create(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
if (!sourceCode.parserServices.isSvelte) { | ||
@@ -39,0 +38,0 @@ return {}; |
import { createRule } from '../utils/index.js'; | ||
import { getCwd, getSourceCode } from '../utils/compat.js'; | ||
export default createRule('valid-style-parse', { | ||
@@ -15,7 +14,7 @@ meta: { | ||
create(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
if (!sourceCode.parserServices.isSvelte) { | ||
return {}; | ||
} | ||
const cwd = `${getCwd(context)}/`; | ||
const cwd = `${context.cwd ?? process.cwd()}/`; | ||
return { | ||
@@ -22,0 +21,0 @@ SvelteStyleElement(node) { |
import { isOpeningParenToken } from '@eslint-community/eslint-utils'; | ||
import { getSourceCode } from '../../utils/compat.js'; | ||
/** Extract comments */ | ||
export function extractLeadingComments(context, node) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const beforeToken = sourceCode.getTokenBefore(node, { | ||
@@ -7,0 +6,0 @@ includeComments: false, |
@@ -1,2 +0,1 @@ | ||
import { getSourceCode } from '../../utils/compat.js'; | ||
const SVELTE_IGNORE_PATTERN = /^\s*svelte-ignore/m; | ||
@@ -20,3 +19,3 @@ /** | ||
export function getSvelteIgnoreItems(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const ignoreComments = []; | ||
@@ -23,0 +22,0 @@ for (const comment of sourceCode.getAllComments()) { |
@@ -16,3 +16,2 @@ import * as compiler from 'svelte/compiler'; | ||
import semver from 'semver'; | ||
import { getSourceCode } from '../../utils/compat.js'; | ||
const STYLE_TRANSFORMS = { | ||
@@ -38,3 +37,3 @@ postcss: transformWithPostCSS, | ||
export function getSvelteCompileWarnings(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const cache = cacheAll.get(sourceCode.ast); | ||
@@ -52,3 +51,3 @@ if (cache) { | ||
function getSvelteCompileWarningsWithoutCache(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
// Process for styles | ||
@@ -61,3 +60,3 @@ const styleElementsWithNotCSS = [...extractStyleElementsWithLangOtherThanCSS(context)]; | ||
if (transform) { | ||
const result = transform(style.node, getSourceCode(context).text, context); | ||
const result = transform(style.node, context.sourceCode.text, context); | ||
if (result) { | ||
@@ -231,3 +230,3 @@ transformResults.push(result); | ||
function* extractStyleElementsWithLangOtherThanCSS(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const root = sourceCode.ast; | ||
@@ -247,3 +246,3 @@ for (const node of root.body) { | ||
function buildStrippedText(context, ignoreComments, stripStyleTokens) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const baseText = sourceCode.text; | ||
@@ -274,3 +273,3 @@ const stripTokens = new Set([...ignoreComments.map((item) => item.token), ...stripStyleTokens]); | ||
: null; | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
if (transform) { | ||
@@ -308,3 +307,3 @@ const root = sourceCode.ast; | ||
? { customElement: true } | ||
: hasTagOption(getSourceCode(context).ast) | ||
: hasTagOption(context.sourceCode.ast) | ||
? { customElement: true } | ||
@@ -338,3 +337,3 @@ : {}) | ||
} | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const unusedIgnores = new Set(ignoreComments); | ||
@@ -454,3 +453,3 @@ const remainingWarning = new Set(warnings); | ||
function isUseTypeScript(context) { | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
if (sourceCode.parserServices.esTreeNodeToTSNodeMap) | ||
@@ -477,3 +476,3 @@ return true; | ||
} | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const root = sourceCode.ast; | ||
@@ -480,0 +479,0 @@ let scriptLang = 'js'; |
import { loadModule } from '../../../utils/load-module.js'; | ||
import { getCwd } from '../../../utils/compat.js'; | ||
/** | ||
@@ -26,3 +25,3 @@ * Transpile with babel | ||
code: true, | ||
cwd: getCwd(context) | ||
cwd: context.cwd ?? process.cwd() | ||
}); | ||
@@ -29,0 +28,0 @@ if (!output) { |
import { loadModule } from '../../../utils/load-module.js'; | ||
import { getFilename } from '../../../utils/compat.js'; | ||
/** | ||
@@ -19,3 +18,3 @@ * Transpile with less | ||
const code = text.slice(...inputRange); | ||
const filename = `${getFilename(context)}.less`; | ||
const filename = `${context.filename}.less`; | ||
try { | ||
@@ -22,0 +21,0 @@ let output; |
import postcss from 'postcss'; | ||
import postcssLoadConfig from 'postcss-load-config'; | ||
import { getCwd, getFilename } from '../../../utils/compat.js'; | ||
/** | ||
@@ -20,7 +19,7 @@ * Transform with postcss | ||
const code = text.slice(...inputRange); | ||
const filename = `${getFilename(context)}.css`; | ||
const filename = `${context.filename}.css`; | ||
try { | ||
const configFilePath = postcssConfig?.configFilePath; | ||
const config = postcssLoadConfig.sync({ | ||
cwd: getCwd(context), | ||
cwd: context.cwd ?? process.cwd(), | ||
from: filename | ||
@@ -27,0 +26,0 @@ }, typeof configFilePath === 'string' ? configFilePath : undefined); |
import { loadModule } from '../../../utils/load-module.js'; | ||
import { getFilename } from '../../../utils/compat.js'; | ||
/** | ||
@@ -19,3 +18,3 @@ * Transpile with stylus | ||
const code = text.slice(...inputRange); | ||
const filename = `${getFilename(context)}.stylus`; | ||
const filename = `${context.filename}.stylus`; | ||
try { | ||
@@ -22,0 +21,0 @@ let output; |
import { loadModule } from '../../../utils/load-module.js'; | ||
import { getSourceCode } from '../../../utils/compat.js'; | ||
/** | ||
@@ -23,3 +22,3 @@ * Transpile with typescript | ||
compilerOptions: { | ||
target: getSourceCode(context).parserServices.program?.getCompilerOptions()?.target || | ||
target: context.sourceCode.parserServices.program?.getCompilerOptions()?.target || | ||
ts.ScriptTarget.ESNext, | ||
@@ -26,0 +25,0 @@ module: ts.ModuleKind.ESNext, |
@@ -121,9 +121,9 @@ import type { JSONSchema4 } from 'json-schema'; | ||
getDeclaredVariables(node: TSESTree.Node): Variable[]; | ||
getFilename(): string; | ||
filename: string; | ||
getScope(): Scope; | ||
getSourceCode(): SourceCode; | ||
sourceCode: SourceCode; | ||
markVariableAsUsed(name: string): boolean; | ||
report(descriptor: ReportDescriptor): void; | ||
getCwd?: () => string; | ||
getPhysicalFilename?: () => string; | ||
cwd?: string; | ||
physicalFilename: string; | ||
}; | ||
@@ -130,0 +130,0 @@ export type NodeOrToken = { |
import * as eslintUtils from '@eslint-community/eslint-utils'; | ||
import { voidElements, svgElements, mathmlElements } from './element-types.js'; | ||
import { getSourceCode } from './compat.js'; | ||
/** | ||
@@ -218,3 +217,3 @@ * Checks whether or not the tokens of two given nodes are same. | ||
export function getScope(context, currentNode) { | ||
const scopeManager = getSourceCode(context).scopeManager; | ||
const scopeManager = context.sourceCode.scopeManager; | ||
let node = currentNode; | ||
@@ -473,3 +472,3 @@ for (; node; node = node.parent || null) { | ||
} | ||
return getSourceCode(context).getText(node); | ||
return context.sourceCode.getText(node); | ||
} | ||
@@ -476,0 +475,0 @@ /** |
import Parser from './template-safe-parser.js'; | ||
import { Input } from 'postcss'; | ||
import { getSourceCode } from '../compat.js'; | ||
/** Parse for CSS */ | ||
@@ -29,3 +28,3 @@ function safeParseCss(css) { | ||
const startOffset = node.value[0].range[0]; | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const cssCode = node.value.map((value) => sourceCode.getText(value)).join(''); | ||
@@ -130,3 +129,3 @@ const root = safeParseCss(cssCode); | ||
} | ||
const sourceCode = getSourceCode(ctx.context); | ||
const sourceCode = ctx.context.sourceCode; | ||
inlineStyles.set(node, null); | ||
@@ -266,5 +265,5 @@ let converted; | ||
return { | ||
start: getSourceCode(ctx.context).getLocFromIndex(range[0]), | ||
end: getSourceCode(ctx.context).getLocFromIndex(range[1]) | ||
start: ctx.context.sourceCode.getLocFromIndex(range[0]), | ||
end: ctx.context.sourceCode.getLocFromIndex(range[1]) | ||
}; | ||
} |
import Module from 'module'; | ||
import path from 'path'; | ||
import { getCwd, getFilename, getPhysicalFilename, getSourceCode } from './compat.js'; | ||
const cache = new WeakMap(); | ||
@@ -10,3 +9,3 @@ const cache4b = new Map(); | ||
export function loadModule(context, name) { | ||
const key = getSourceCode(context).ast; | ||
const key = context.sourceCode.ast; | ||
let modules = cache.get(key); | ||
@@ -22,3 +21,3 @@ if (!modules) { | ||
// load from cwd | ||
const cwd = getCwd(context); | ||
const cwd = context.cwd ?? process.cwd(); | ||
const relativeTo = path.join(cwd, '__placeholder__.js'); | ||
@@ -32,5 +31,5 @@ return (modules[name] = Module.createRequire(relativeTo)(name)); | ||
// load from lint file name | ||
getFilename(context), | ||
context.filename, | ||
// load from lint file name (physical) | ||
getPhysicalFilename(context), | ||
context.physicalFilename, | ||
// load from this plugin module | ||
@@ -37,0 +36,0 @@ typeof __filename !== 'undefined' ? __filename : '' |
@@ -5,3 +5,2 @@ import fs from 'fs'; | ||
import { getNodeModule } from './get-node-module.js'; | ||
import { getFilename, getSourceCode } from './compat.js'; | ||
import { createCache } from './cache.js'; | ||
@@ -71,3 +70,3 @@ import { VERSION as SVELTE_VERSION } from 'svelte/compiler'; | ||
function getSvelteKitContext(context) { | ||
const filePath = getFilename(context); | ||
const filePath = context.filename; | ||
const cached = svelteKitContextCache.get(filePath); | ||
@@ -95,4 +94,4 @@ if (cached) | ||
const routes = (context.settings?.svelte?.kit?.files?.routes ?? | ||
getSourceCode(context).parserServices.svelteParseContext?.svelteConfig?.kit?.files?.routes)?.replace(/^\//, '') ?? 'src/routes'; | ||
const projectRootDir = getProjectRootDir(getFilename(context)) ?? ''; | ||
context.sourceCode.parserServices.svelteParseContext?.svelteConfig?.kit?.files?.routes)?.replace(/^\//, '') ?? 'src/routes'; | ||
const projectRootDir = getProjectRootDir(context.filename) ?? ''; | ||
if (!filePath.startsWith(path.join(projectRootDir, routes))) { | ||
@@ -213,5 +212,5 @@ const result = { | ||
export function getSvelteContext(context) { | ||
const { parserServices } = getSourceCode(context); | ||
const { parserServices } = context.sourceCode; | ||
const { svelteParseContext } = parserServices; | ||
const filePath = getFilename(context); | ||
const filePath = context.filename; | ||
const cached = svelteContextCache.get(filePath); | ||
@@ -218,0 +217,0 @@ if (cached) |
import { loadModule } from '../load-module.js'; | ||
import { getSourceCode } from '../compat.js'; | ||
/** | ||
@@ -11,3 +10,3 @@ * Get TypeScript tools | ||
} | ||
const sourceCode = getSourceCode(context); | ||
const sourceCode = context.sourceCode; | ||
const { program, esTreeNodeToTSNodeMap, tsNodeToESTreeNodeMap } = sourceCode.parserServices; | ||
@@ -14,0 +13,0 @@ if (!program || !esTreeNodeToTSNodeMap || !tsNodeToESTreeNodeMap) { |
{ | ||
"name": "eslint-plugin-svelte", | ||
"version": "3.4.0", | ||
"version": "3.4.1", | ||
"description": "ESLint plugin for Svelte using AST", | ||
@@ -5,0 +5,0 @@ "repository": "git+https://github.com/sveltejs/eslint-plugin-svelte.git", |
760152
-0.76%251
-0.79%17732
-0.61%