eslint-plugin-svelte3
Advanced tools
Comparing version 2.0.2 to 2.1.0
@@ -0,1 +1,5 @@ | ||
# 2.1.0 | ||
- Preserve linting messages about labels other than `$` | ||
# 2.0.2 | ||
@@ -2,0 +6,0 @@ |
30
index.js
@@ -5,3 +5,3 @@ 'use strict'; | ||
let compiler_options, messages, transformed_code, ignore_warnings, ignore_styles, translations; | ||
let compiler_options, messages, transformed_code, line_offsets, ignore_warnings, ignore_styles, translations; | ||
@@ -271,2 +271,20 @@ // get the total length, number of lines, and length of the last line of a string | ||
// extract the string referenced by a message | ||
const get_referenced_string = message => { | ||
if (message.line && message.column && message.endLine && message.endColumn) { | ||
if (!line_offsets) { | ||
line_offsets = [-1, -1]; | ||
for (let i = 0; i < transformed_code.length; i++) { | ||
if (transformed_code[i] === '\n') { | ||
line_offsets.push(i); | ||
} | ||
} | ||
} | ||
return transformed_code.slice(line_offsets[message.line] + message.column, line_offsets[message.endLine] + message.endColumn); | ||
} | ||
}; | ||
// extract something that looks like an identifier (minus insane unicode stuff) from the beginning of a string | ||
const get_identifier = str => (str && str.match(/^[a-zA-Z_$][0-9a-zA-Z_$]*/) || [])[0]; | ||
// determine whether this message from ESLint is something we care about | ||
@@ -276,6 +294,6 @@ const is_valid_message = message => { | ||
case 'eol-last': return false; | ||
case 'no-labels': return false; | ||
case 'no-restricted-syntax': return message.nodeType !== 'LabeledStatement'; | ||
case 'no-labels': return get_identifier(get_referenced_string(message)) !== '$'; | ||
case 'no-restricted-syntax': return message.nodeType !== 'LabeledStatement' || get_identifier(get_referenced_string(message)) !== '$'; | ||
case 'no-self-assign': return false; | ||
case 'no-unused-labels': return !message.message.includes("'$:'"); | ||
case 'no-unused-labels': return get_referenced_string(message) !== '$'; | ||
} | ||
@@ -303,3 +321,5 @@ return true; | ||
// sort messages and return | ||
return messages.sort((a, b) => a.line - b.line || a.column - b.column); | ||
const sorted_messages = messages.sort((a, b) => a.line - b.line || a.column - b.column); | ||
compiler_options = messages = transformed_code = line_offsets = ignore_warnings = ignore_styles = translations = null; | ||
return sorted_messages; | ||
}; | ||
@@ -306,0 +326,0 @@ |
{ | ||
"name": "eslint-plugin-svelte3", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "An ESLint plugin for Svelte v3 components.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
20232
319