initial commit of actions
This commit is contained in:
commit
949ece5785
44660 changed files with 12034344 additions and 0 deletions
211
github/codeql-action-v2/node_modules/eslint-plugin-eslint-comments/lib/internal/disabled-area.js
generated
vendored
Normal file
211
github/codeql-action-v2/node_modules/eslint-plugin-eslint-comments/lib/internal/disabled-area.js
generated
vendored
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
/**
|
||||
* @author Toru Nagashima <https://github.com/mysticatea>
|
||||
* See LICENSE file in root directory for full license.
|
||||
*/
|
||||
"use strict"
|
||||
|
||||
const utils = require("./utils")
|
||||
const DELIMITER = /[\s,]+/gu
|
||||
const pool = new WeakMap()
|
||||
|
||||
module.exports = class DisabledArea {
|
||||
/**
|
||||
* Get singleton instance for the given source code.
|
||||
*
|
||||
* @param {eslint.SourceCode} sourceCode - The source code to get.
|
||||
* @returns {DisabledArea} The singleton object for the source code.
|
||||
*/
|
||||
static get(sourceCode) {
|
||||
let retv = pool.get(sourceCode.ast)
|
||||
|
||||
if (retv == null) {
|
||||
retv = new DisabledArea()
|
||||
retv._scan(sourceCode)
|
||||
pool.set(sourceCode.ast, retv)
|
||||
}
|
||||
|
||||
return retv
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
constructor() {
|
||||
this.areas = []
|
||||
this.duplicateDisableDirectives = []
|
||||
this.unusedEnableDirectives = []
|
||||
this.numberOfRelatedDisableDirectives = new Map()
|
||||
}
|
||||
|
||||
/**
|
||||
* Make disabled area.
|
||||
*
|
||||
* @param {Token} comment - The comment token to disable.
|
||||
* @param {object} location - The start location to disable.
|
||||
* @param {string[]|null} ruleIds - The ruleId names to disable.
|
||||
* @param {string} kind - The kind of disable-comments.
|
||||
* @returns {void}
|
||||
* @private
|
||||
*/
|
||||
_disable(comment, location, ruleIds, kind) {
|
||||
if (ruleIds) {
|
||||
for (const ruleId of ruleIds) {
|
||||
if (this._getArea(ruleId, location) != null) {
|
||||
this.duplicateDisableDirectives.push({ comment, ruleId })
|
||||
}
|
||||
|
||||
this.areas.push({
|
||||
comment,
|
||||
ruleId,
|
||||
kind,
|
||||
start: location,
|
||||
end: null,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (this._getArea(null, location) != null) {
|
||||
this.duplicateDisableDirectives.push({ comment, ruleId: null })
|
||||
}
|
||||
|
||||
this.areas.push({
|
||||
comment,
|
||||
ruleId: null,
|
||||
kind,
|
||||
start: location,
|
||||
end: null,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close disabled area.
|
||||
*
|
||||
* @param {Token} comment - The comment token to enable.
|
||||
* @param {object} location - The start location to enable.
|
||||
* @param {string[]|null} ruleIds - The ruleId names to enable.
|
||||
* @param {string} kind - The kind of disable-comments.
|
||||
* @returns {void}
|
||||
* @private
|
||||
*/
|
||||
_enable(comment, location, ruleIds, kind) {
|
||||
const relatedDisableDirectives = new Set()
|
||||
|
||||
if (ruleIds) {
|
||||
for (const ruleId of ruleIds) {
|
||||
let used = false
|
||||
|
||||
for (let i = this.areas.length - 1; i >= 0; --i) {
|
||||
const area = this.areas[i]
|
||||
|
||||
if (
|
||||
area.end === null &&
|
||||
area.kind === kind &&
|
||||
area.ruleId === ruleId
|
||||
) {
|
||||
relatedDisableDirectives.add(area.comment)
|
||||
area.end = location
|
||||
used = true
|
||||
}
|
||||
}
|
||||
|
||||
if (!used) {
|
||||
this.unusedEnableDirectives.push({ comment, ruleId })
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let used = false
|
||||
|
||||
for (let i = this.areas.length - 1; i >= 0; --i) {
|
||||
const area = this.areas[i]
|
||||
|
||||
if (area.end === null && area.kind === kind) {
|
||||
relatedDisableDirectives.add(area.comment)
|
||||
area.end = location
|
||||
used = true
|
||||
}
|
||||
}
|
||||
|
||||
if (!used) {
|
||||
this.unusedEnableDirectives.push({ comment, ruleId: null })
|
||||
}
|
||||
}
|
||||
|
||||
this.numberOfRelatedDisableDirectives.set(
|
||||
comment,
|
||||
relatedDisableDirectives.size
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the area of the given ruleId and location.
|
||||
*
|
||||
* @param {string|null} ruleId - The ruleId name to get.
|
||||
* @param {object} location - The location to get.
|
||||
* @returns {object|null} The area of the given ruleId and location.
|
||||
* @private
|
||||
*/
|
||||
_getArea(ruleId, location) {
|
||||
for (let i = this.areas.length - 1; i >= 0; --i) {
|
||||
const area = this.areas[i]
|
||||
|
||||
if (
|
||||
(area.ruleId === null || area.ruleId === ruleId) &&
|
||||
utils.lte(area.start, location) &&
|
||||
(area.end === null || utils.lte(location, area.end))
|
||||
) {
|
||||
return area
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan the source code and setup disabled area list.
|
||||
*
|
||||
* @param {eslint.SourceCode} sourceCode - The source code to scan.
|
||||
* @returns {void}
|
||||
* @private
|
||||
*/
|
||||
_scan(sourceCode) {
|
||||
for (const comment of sourceCode.getAllComments()) {
|
||||
const directiveComment = utils.parseDirectiveComment(comment)
|
||||
if (directiveComment == null) {
|
||||
continue
|
||||
}
|
||||
|
||||
const kind = directiveComment.kind
|
||||
if (
|
||||
kind !== "eslint-disable" &&
|
||||
kind !== "eslint-enable" &&
|
||||
kind !== "eslint-disable-line" &&
|
||||
kind !== "eslint-disable-next-line"
|
||||
) {
|
||||
continue
|
||||
}
|
||||
const ruleIds = directiveComment.value
|
||||
? directiveComment.value.split(DELIMITER)
|
||||
: null
|
||||
|
||||
if (kind === "eslint-disable") {
|
||||
this._disable(comment, comment.loc.start, ruleIds, "block")
|
||||
} else if (kind === "eslint-enable") {
|
||||
this._enable(comment, comment.loc.start, ruleIds, "block")
|
||||
} else if (kind === "eslint-disable-line") {
|
||||
const line = comment.loc.start.line
|
||||
const start = { line, column: 0 }
|
||||
const end = { line: line + 1, column: -1 }
|
||||
|
||||
this._disable(comment, start, ruleIds, "line")
|
||||
this._enable(comment, end, ruleIds, "line")
|
||||
} else if (kind === "eslint-disable-next-line") {
|
||||
const line = comment.loc.start.line
|
||||
const start = { line: line + 1, column: 0 }
|
||||
const end = { line: line + 2, column: -1 }
|
||||
|
||||
this._disable(comment, start, ruleIds, "line")
|
||||
this._enable(comment, end, ruleIds, "line")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
github/codeql-action-v2/node_modules/eslint-plugin-eslint-comments/lib/internal/get-linters.js
generated
vendored
Normal file
33
github/codeql-action-v2/node_modules/eslint-plugin-eslint-comments/lib/internal/get-linters.js
generated
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* @author Toru Nagashima <https://github.com/mysticatea>
|
||||
* See LICENSE file in root directory for full license.
|
||||
*/
|
||||
"use strict"
|
||||
|
||||
const path = require("path")
|
||||
const needle = `${path.sep}node_modules${path.sep}eslint${path.sep}`
|
||||
|
||||
module.exports = () => {
|
||||
const eslintPaths = new Set(
|
||||
Object.keys(require.cache)
|
||||
.filter(id => id.includes(needle))
|
||||
.map(id => id.slice(0, id.indexOf(needle) + needle.length))
|
||||
)
|
||||
const linters = []
|
||||
|
||||
for (const eslintPath of eslintPaths) {
|
||||
try {
|
||||
const linter = require(eslintPath).Linter
|
||||
|
||||
if (linter) {
|
||||
linters.push(linter)
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.code !== "MODULE_NOT_FOUND") {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return linters
|
||||
}
|
||||
152
github/codeql-action-v2/node_modules/eslint-plugin-eslint-comments/lib/internal/utils.js
generated
vendored
Normal file
152
github/codeql-action-v2/node_modules/eslint-plugin-eslint-comments/lib/internal/utils.js
generated
vendored
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
/**
|
||||
* @author Toru Nagashima <https://github.com/mysticatea>
|
||||
* See LICENSE file in root directory for full license.
|
||||
*/
|
||||
"use strict"
|
||||
|
||||
const escapeStringRegexp = require("escape-string-regexp")
|
||||
const LINE_PATTERN = /[^\r\n\u2028\u2029]*(?:\r\n|[\r\n\u2028\u2029]|$)/gu
|
||||
|
||||
const DIRECTIVE_PATTERN = /^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u
|
||||
const LINE_COMMENT_PATTERN = /^eslint-disable-(next-)?line$/u
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Make the location ignoring `eslint-disable` comments.
|
||||
*
|
||||
* @param {object} location - The location to convert.
|
||||
* @returns {object} Converted location.
|
||||
*/
|
||||
toForceLocation(location) {
|
||||
return {
|
||||
start: {
|
||||
line: location.start.line,
|
||||
column: -1,
|
||||
},
|
||||
end: location.end,
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the location of the given rule in the given comment token.
|
||||
*
|
||||
* @param {Token} comment - The comment token to calculate.
|
||||
* @param {string|null} ruleId - The rule name to calculate.
|
||||
* @returns {object} The location of the given information.
|
||||
*/
|
||||
toRuleIdLocation(comment, ruleId) {
|
||||
if (ruleId == null) {
|
||||
return module.exports.toForceLocation(comment.loc)
|
||||
}
|
||||
|
||||
const lines = comment.value.match(LINE_PATTERN)
|
||||
//eslint-disable-next-line require-unicode-regexp
|
||||
const ruleIdPattern = new RegExp(
|
||||
`([\\s,]|^)${escapeStringRegexp(ruleId)}(?:[\\s,]|$)`
|
||||
)
|
||||
|
||||
{
|
||||
const m = ruleIdPattern.exec(lines[0])
|
||||
if (m != null) {
|
||||
const start = comment.loc.start
|
||||
return {
|
||||
start: {
|
||||
line: start.line,
|
||||
column: 2 + start.column + m.index + m[1].length,
|
||||
},
|
||||
end: {
|
||||
line: start.line,
|
||||
column:
|
||||
2 +
|
||||
start.column +
|
||||
m.index +
|
||||
m[1].length +
|
||||
ruleId.length,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 1; i < lines.length; ++i) {
|
||||
const m = ruleIdPattern.exec(lines[i])
|
||||
if (m != null) {
|
||||
const start = comment.loc.start
|
||||
return {
|
||||
start: {
|
||||
line: start.line + i,
|
||||
column: m.index + m[1].length,
|
||||
},
|
||||
end: {
|
||||
line: start.line + i,
|
||||
column: m.index + m[1].length + ruleId.length,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*istanbul ignore next : foolproof */
|
||||
return comment.loc
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks `a` is less than `b` or `a` equals `b`.
|
||||
*
|
||||
* @param {{line: number, column: number}} a - A location to compare.
|
||||
* @param {{line: number, column: number}} b - Another location to compare.
|
||||
* @returns {boolean} `true` if `a` is less than `b` or `a` equals `b`.
|
||||
*/
|
||||
lte(a, b) {
|
||||
return a.line < b.line || (a.line === b.line && a.column <= b.column)
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse the given comment token as a directive comment.
|
||||
*
|
||||
* @param {Token} comment - The comment token to parse.
|
||||
* @returns {{kind: string, value: string, description: string | null}|null} The parsed data of the given comment. If `null`, it is not a directive comment.
|
||||
*/
|
||||
parseDirectiveComment(comment) {
|
||||
const { text, description } = divideDirectiveComment(comment.value)
|
||||
const match = DIRECTIVE_PATTERN.exec(text)
|
||||
|
||||
if (!match) {
|
||||
return null
|
||||
}
|
||||
const directiveText = match[1]
|
||||
const lineCommentSupported = LINE_COMMENT_PATTERN.test(directiveText)
|
||||
|
||||
if (comment.type === "Line" && !lineCommentSupported) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (
|
||||
lineCommentSupported &&
|
||||
comment.loc.start.line !== comment.loc.end.line
|
||||
) {
|
||||
// disable-line comment should not span multiple lines.
|
||||
return null
|
||||
}
|
||||
|
||||
const directiveValue = text.slice(match.index + directiveText.length)
|
||||
|
||||
return {
|
||||
kind: directiveText,
|
||||
value: directiveValue.trim(),
|
||||
description,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Divides and trims description text and directive comments.
|
||||
* @param {string} value The comment text to strip.
|
||||
* @returns {{text: string, description: string | null}} The stripped text.
|
||||
*/
|
||||
function divideDirectiveComment(value) {
|
||||
const divided = value.split(/\s-{2,}\s/u)
|
||||
const text = divided[0].trim()
|
||||
return {
|
||||
text,
|
||||
description: divided.length > 1 ? divided[1].trim() : null,
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue