eslint-plugin-vue
Advanced tools
Comparing version
@@ -61,2 +61,3 @@ /* | ||
'define-props-declaration': require('./rules/define-props-declaration'), | ||
'define-props-destructuring': require('./rules/define-props-destructuring'), | ||
'dot-location': require('./rules/dot-location'), | ||
@@ -63,0 +64,0 @@ 'dot-notation': require('./rules/dot-notation'), |
@@ -152,14 +152,30 @@ /** | ||
/** @type {string[]} */ | ||
const allowlist = opts.allowlist || DEFAULT_ALLOWLIST | ||
const rawAllowlist = opts.allowlist || DEFAULT_ALLOWLIST | ||
const attributes = parseTargetAttrs(opts.attributes || DEFAULT_ATTRIBUTES) | ||
const directives = opts.directives || DEFAULT_DIRECTIVES | ||
const allowlistRe = new RegExp( | ||
allowlist | ||
.map((w) => regexp.escape(w)) | ||
.sort((a, b) => b.length - a.length) | ||
.join('|'), | ||
'gu' | ||
) | ||
/** @type {string[]} */ | ||
const stringAllowlist = [] | ||
/** @type {RegExp[]} */ | ||
const regexAllowlist = [] | ||
for (const item of rawAllowlist) { | ||
if (regexp.isRegExp(item)) { | ||
regexAllowlist.push(regexp.toRegExp(item)) | ||
} else { | ||
stringAllowlist.push(item) | ||
} | ||
} | ||
const allowlistRe = | ||
stringAllowlist.length > 0 | ||
? new RegExp( | ||
stringAllowlist | ||
.map((w) => regexp.escape(w)) | ||
.sort((a, b) => b.length - a.length) | ||
.join('|'), | ||
'gu' | ||
) | ||
: null | ||
/** @type {ElementStack | null} */ | ||
@@ -172,3 +188,17 @@ let elementStack = null | ||
function getBareString(str) { | ||
return str.trim().replace(allowlistRe, '').trim() | ||
let result = str.trim() | ||
if (allowlistRe) { | ||
result = result.replace(allowlistRe, '') | ||
} | ||
for (const regex of regexAllowlist) { | ||
const flags = regex.flags.includes('g') | ||
? regex.flags | ||
: `${regex.flags}g` | ||
const globalRegex = new RegExp(regex.source, flags) | ||
result = result.replace(globalRegex, '') | ||
} | ||
return result.trim() | ||
} | ||
@@ -175,0 +205,0 @@ |
@@ -9,2 +9,17 @@ /** | ||
/** | ||
* Get all comments that need to be reported | ||
* @param {(HTMLComment | HTMLBogusComment | Comment)[]} comments | ||
* @param {Range[]} elementRanges | ||
* @returns {(HTMLComment | HTMLBogusComment | Comment)[]} | ||
*/ | ||
function getReportComments(comments, elementRanges) { | ||
return comments.filter( | ||
(comment) => | ||
!elementRanges.some( | ||
(range) => range[0] <= comment.range[0] && comment.range[1] <= range[1] | ||
) | ||
) | ||
} | ||
module.exports = { | ||
@@ -19,4 +34,15 @@ meta: { | ||
fixable: null, | ||
schema: [], | ||
schema: [ | ||
{ | ||
type: 'object', | ||
properties: { | ||
disallowComments: { | ||
type: 'boolean' | ||
} | ||
}, | ||
additionalProperties: false | ||
} | ||
], | ||
messages: { | ||
commentRoot: 'The template root disallows comments.', | ||
multipleRoot: 'The template root requires exactly one element.', | ||
@@ -33,2 +59,4 @@ textRoot: 'The template root requires an element rather than texts.', | ||
create(context) { | ||
const options = context.options[0] || {} | ||
const disallowComments = options.disallowComments | ||
const sourceCode = context.getSourceCode() | ||
@@ -43,2 +71,14 @@ | ||
const comments = element.comments | ||
const elementRanges = element.children.map((child) => child.range) | ||
if (disallowComments && comments.length > 0) { | ||
for (const comment of getReportComments(comments, elementRanges)) { | ||
context.report({ | ||
node: comment, | ||
loc: comment.loc, | ||
messageId: 'commentRoot' | ||
}) | ||
} | ||
} | ||
const rootElements = [] | ||
@@ -45,0 +85,0 @@ let extraText = null |
{ | ||
"name": "eslint-plugin-vue", | ||
"version": "10.0.1", | ||
"version": "10.1.0", | ||
"description": "Official ESLint plugin for Vue.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
1385717
0.3%320
0.31%45268
0.3%