eslint-plugin-svelte3
Advanced tools
Comparing version 3.1.2 to 3.2.0
@@ -0,1 +1,9 @@ | ||
# 3.2.0 | ||
- Support lazy-loading TypeScript compiler | ||
- Support non-CommonJS format of ESLint configuration file when using TypeScript by specifying `true` in configuration | ||
- Improve logic for finding the correct `Linter` instance in a workspace with multiple directories | ||
- Improve filtering of `@typescript-eslint/indent` and `@typescript-eslint/quotes` messages like what already happens with `indent` and `quotes` | ||
- Fix erroneous messages when a component only writes to a store | ||
# 3.1.2 | ||
@@ -2,0 +10,0 @@ |
32
index.js
@@ -55,3 +55,3 @@ 'use strict'; | ||
// get character offsets of each line in a string | ||
const get_line_offsets = str => { | ||
const get_line_offsets$1 = str => { | ||
const offsets = [-1]; | ||
@@ -88,6 +88,11 @@ for (let i = 0; i < str.length; i++) { | ||
// find Linter instance | ||
const linter_path = Object.keys(require.cache).find(path => path.endsWith('/eslint/lib/linter/linter.js') || path.endsWith('\\eslint\\lib\\linter\\linter.js')); | ||
if (!linter_path) { | ||
const linter_paths = Object.keys(require.cache).filter(path => path.endsWith('/eslint/lib/linter/linter.js') || path.endsWith('\\eslint\\lib\\linter\\linter.js')); | ||
if (!linter_paths.length) { | ||
throw new Error('Could not find ESLint Linter in require cache'); | ||
} | ||
// There may be more than one instance of the linter when we're in a workspace with multiple directories. | ||
// We first try to find the one that's inside the same node_modules directory as this plugin. | ||
// If that can't be found for some reason, we assume the one we want is the last one in the array. | ||
const current_node_modules_path = __dirname.replace(/(?<=[/\\]node_modules[/\\]).*$/, ''); | ||
const linter_path = linter_paths.find(path => path.startsWith(current_node_modules_path)) || linter_paths.pop(); | ||
const { Linter } = require(linter_path); | ||
@@ -105,3 +110,8 @@ | ||
processor_options.named_blocks = settings['svelte3/named-blocks']; | ||
processor_options.typescript = settings['svelte3/typescript']; | ||
processor_options.typescript = | ||
settings['svelte3/typescript'] === true | ||
? require('typescript') | ||
: typeof settings['svelte3/typescript'] === 'function' | ||
? settings['svelte3/typescript']() | ||
: settings['svelte3/typescript']; | ||
// call original Linter#verify | ||
@@ -331,3 +341,3 @@ return verify.call(this, code, config, options); | ||
function offset_at(position, text) { | ||
const line_offsets = get_line_offsets$1(text); | ||
const line_offsets = get_line_offsets(text); | ||
@@ -350,3 +360,3 @@ if (position.line >= line_offsets.length) { | ||
const line_offsets = get_line_offsets$1(text); | ||
const line_offsets = get_line_offsets(text); | ||
let low = 0; | ||
@@ -373,3 +383,3 @@ let high = line_offsets.length; | ||
function get_line_offsets$1(text) { | ||
function get_line_offsets(text) { | ||
const line_offsets = []; | ||
@@ -461,3 +471,3 @@ let is_line_start = true; | ||
const references_and_reassignments = `{${vars.filter(v => v.referenced).map(v => v.name)};${vars.filter(v => v.reassigned || v.export_name).map(v => v.name + '=0')}}`; | ||
const references_and_reassignments = `{${vars.filter(v => v.referenced || v.name[0] === '$').map(v => v.name)};${vars.filter(v => v.reassigned || v.export_name).map(v => v.name + '=0')}}`; | ||
state.var_names = new Set(vars.map(v => v.name)); | ||
@@ -583,3 +593,3 @@ | ||
block.transformed_code += `{${vars.filter(v => v.referenced_from_script).map(v => v.name)}}`; | ||
block.transformed_code += `{${vars.filter(v => v.referenced_from_script || v.name[0] === '$').map(v => v.name)}}`; | ||
} | ||
@@ -764,3 +774,3 @@ | ||
if (!block.line_offsets) { | ||
block.line_offsets = get_line_offsets(block.transformed_code); | ||
block.line_offsets = get_line_offsets$1(block.transformed_code); | ||
} | ||
@@ -778,2 +788,3 @@ return block.transformed_code.slice(block.line_offsets[message.line - 1] + message.column, block.line_offsets[message.endLine - 1] + message.endColumn); | ||
case 'eol-last': return false; | ||
case '@typescript-eslint/indent': | ||
case 'indent': return !translation.options.template; | ||
@@ -785,2 +796,3 @@ case 'linebreak-style': return message.line !== translation.end; | ||
case 'no-unused-labels': return get_referenced_string(block, message) !== '$'; | ||
case '@typescript-eslint/quotes': | ||
case 'quotes': return !translation.options.in_quoted_attribute; | ||
@@ -787,0 +799,0 @@ } |
{ | ||
"name": "eslint-plugin-svelte3", | ||
"version": "3.1.2", | ||
"version": "3.2.0", | ||
"description": "An ESLint plugin for Svelte v3 components.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -80,3 +80,5 @@ # eslint-plugin-svelte3 | ||
settings: { | ||
'svelte3/typescript': require('typescript'), // pass the TypeScript package to the Svelte plugin | ||
'svelte3/typescript': () => require('typescript'), // pass the TypeScript package to the Svelte plugin | ||
// OR | ||
'svelte3/typescript': true, // load TypeScript as peer dependency | ||
// ... | ||
@@ -166,4 +168,8 @@ } | ||
If you use TypeScript inside your Svelte components and want ESLint support, you need to set this option. It expects an instance of the TypeScript package. This probably means doing `'svelte3/typescript': require('typescript')`. | ||
If you use TypeScript inside your Svelte components and want ESLint support, you need to set this option. It expects a function returning an instance of the TypeScript package. This probably means doing `'svelte3/typescript': () => require('typescript')`. | ||
To support ESLint configuration files that are not written in CommonJS, this can also be set to `true`, which behaves the same as `() => require('typescript')`. | ||
For backwards compatibility, it also supports being passed the TypeScript package directly, but this is not generally recommended as it unnecessarily loads the package in some situations. | ||
The default is to not enable TypeScript support. | ||
@@ -170,0 +176,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43602
738
196