Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/NodeCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ jobs:
run: npm ci
- name: Install ESLint ${{ matrix.eslint }}
run: npm i -D eslint@${{ matrix.eslint }}
- name: Build
run: npm run build
- name: Test
run: npm test
test-and-coverage:
Expand Down
17 changes: 14 additions & 3 deletions lib/utils/ast-utils/pattern-source.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { Rule, AST, SourceCode } from "eslint"
import type { Expression, Literal, RegExpLiteral } from "estree"
import type {
Expression,
Literal,
RegExpLiteral,
PrivateIdentifier,
} from "estree"
import {
dereferenceOwnedVariable,
astRangeToLocation,
Expand Down Expand Up @@ -266,6 +271,7 @@ export class PatternSource {
let value = ""

for (const e of flat) {
if (e.type === "PrivateIdentifier") return null
const staticValue = getStaticValue(context, e)
if (!staticValue) {
return null
Expand Down Expand Up @@ -433,10 +439,15 @@ export class PatternSource {
*
* This will automatically dereference owned constants.
*/
function flattenPlus(context: Rule.RuleContext, e: Expression): Expression[] {
function flattenPlus(
context: Rule.RuleContext,
e: Expression,
): (Expression | PrivateIdentifier)[] {
if (e.type === "BinaryExpression" && e.operator === "+") {
return [
...flattenPlus(context, e.left),
...(e.left.type !== "PrivateIdentifier"
? flattenPlus(context, e.left)
: [e.left]),
...flattenPlus(context, e.right),
]
}
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/regexp-ast/is-covered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ function normalizeNodeWithoutCache(

case "Backreference":
case "Flags":
case "ModifierFlags":
case "Modifiers":
return NormalizedOther.fromNode(node)

default:
Expand Down
16 changes: 16 additions & 0 deletions lib/utils/regexp-ast/is-equals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ const EQUALS_CHECKER: {
Group(a, b, flags, shortCircuit) {
return isEqualSet(a.alternatives, b.alternatives, flags, shortCircuit)
},
ModifierFlags(a, b) {
return (
a.dotAll === b.dotAll &&
a.ignoreCase === b.ignoreCase &&
a.multiline === b.multiline
)
},
Modifiers(a, b, flags, shortCircuit) {
return (
isEqualNodes(a.add, b.add, flags, shortCircuit) &&
((a.remove == null && b.remove == null) ||
(a.remove != null &&
b.remove != null &&
isEqualNodes(a.remove, b.remove, flags, shortCircuit)))
)
},
Pattern(a, b, flags, shortCircuit) {
return isEqualSet(a.alternatives, b.alternatives, flags, shortCircuit)
},
Expand Down
6 changes: 5 additions & 1 deletion lib/utils/type-tracker/jsdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ export class JSDoc {
* Get the JSDoc comment for a given expression node.
*/
export function getJSDoc(
node: ES.Expression | ES.VariableDeclarator | ES.FunctionDeclaration,
node:
| ES.Expression
| ES.VariableDeclarator
| ES.FunctionDeclaration
| ES.PrivateIdentifier,
context: Rule.RuleContext,
): JSDoc | null {
const sourceCode = context.sourceCode
Expand Down
17 changes: 13 additions & 4 deletions lib/utils/type-tracker/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export function createTypeTracker(context: Rule.RuleContext): TypeTracker {

const { tsNodeMap, checker, usedTS } = getTypeScriptTools(context)

const cacheTypeInfo = new WeakMap<ES.Expression, TypeInfo | null>()
const cacheTypeInfo = new WeakMap<
ES.Expression | ES.PrivateIdentifier,
TypeInfo | null
>()

const tracker: TypeTracker = {
isString,
Expand Down Expand Up @@ -129,7 +132,9 @@ export function createTypeTracker(context: Rule.RuleContext): TypeTracker {
/**
* Get the type name from given node.
*/
function getType(node: ES.Expression): TypeInfo | null {
function getType(
node: ES.Expression | ES.PrivateIdentifier,
): TypeInfo | null {
if (cacheTypeInfo.has(node)) {
return cacheTypeInfo.get(node) ?? null
}
Expand All @@ -147,7 +152,9 @@ export function createTypeTracker(context: Rule.RuleContext): TypeTracker {
/**
* Get the type name from given node.
*/
function getTypeWithoutCache(node: ES.Expression): TypeInfo | null {
function getTypeWithoutCache(
node: ES.Expression | ES.PrivateIdentifier,
): TypeInfo | null {
if (node.type === "Literal") {
if (typeof node.value === "string") {
return STRING
Expand Down Expand Up @@ -511,7 +518,9 @@ export function createTypeTracker(context: Rule.RuleContext): TypeTracker {
/**
* Get type from given node by ts types.
*/
function getTypeByTs(node: ES.Expression): TypeInfo | null {
function getTypeByTs(
node: ES.Expression | ES.PrivateIdentifier,
): TypeInfo | null {
const tsNode = tsNodeMap.get(node)
const tsType = (tsNode && checker?.getTypeAtLocation(tsNode)) || null
return tsType && getTypeFromTsType(tsType)
Expand Down
5 changes: 2 additions & 3 deletions lib/utils/type-tracker/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Rule } from "eslint"
import type { Variable } from "eslint-scope"
import type { Rule, Scope } from "eslint"
import type * as ES from "estree"
import * as astUtils from "../ast-utils"
import * as eslintUtils from "@eslint-community/eslint-utils"
Expand All @@ -10,7 +9,7 @@ import * as eslintUtils from "@eslint-community/eslint-utils"
export function findVariable(
context: Rule.RuleContext,
node: ES.Identifier,
): Variable | null {
): Scope.Variable | null {
return astUtils.findVariable(context, node)
}
/**
Expand Down
Loading
Loading