forked from mysticatea/eslint-utils
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,317 additions
and
667 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"include": ["src/**/*.mjs"], | ||
"include": ["src/**/*.ts"], | ||
"reporter": ["lcov", "text-summary"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
!.vitepress | ||
/docs/.vitepress/dist | ||
/docs/.vitepress/cache | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
/node_modules | ||
/index.* | ||
/test.* | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { defineBuildConfig } from "unbuild" | ||
|
||
export default defineBuildConfig({ | ||
externals: ["estree"], | ||
hooks: { | ||
"rollup:options"(_ctx, options) { | ||
for (const output of [options.output].flat()) { | ||
if (output!.format === "cjs") { | ||
output!.exports = "named" | ||
} | ||
} | ||
}, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { Scope } from "eslint" | ||
import type * as ESTree from "estree" | ||
import { getInnermostScope } from "./get-innermost-scope" | ||
|
||
/** | ||
* Find the variable of a given name. | ||
* @param initialScope The scope to start finding. | ||
* @param nameOrNode The variable name to find. If this is a Node object then it should be an Identifier node. | ||
* @returns The found variable or null. | ||
*/ | ||
export function findVariable( | ||
initialScope: Scope.Scope, | ||
nameOrNode: ESTree.Identifier | string, | ||
): Scope.Variable | null { | ||
let name = "" | ||
let scope: Scope.Scope | null = initialScope | ||
|
||
if (typeof nameOrNode === "string") { | ||
name = nameOrNode | ||
} else { | ||
name = nameOrNode.name | ||
scope = getInnermostScope(scope, nameOrNode) | ||
} | ||
|
||
while (scope != null) { | ||
const variable = scope.set.get(name) | ||
if (variable != null) { | ||
return variable | ||
} | ||
scope = scope.upper | ||
} | ||
|
||
return null | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import type { SourceCode } from "eslint" | ||
import type * as ESTree from "estree" | ||
import { getParent } from "./get-parent" | ||
import { isArrowToken, isOpeningParenToken } from "./token-predicate" | ||
|
||
/** | ||
* Get the `(` token of the given function node. | ||
* @param node - The function node to get. | ||
* @param sourceCode - The source code object to get tokens. | ||
* @returns `(` token. | ||
*/ | ||
function getOpeningParenOfParams( | ||
node: ESTree.Function, | ||
sourceCode: SourceCode, | ||
) { | ||
return node.type !== "ArrowFunctionExpression" && node.id | ||
? sourceCode.getTokenAfter(node.id, isOpeningParenToken)! | ||
: sourceCode.getFirstToken(node, isOpeningParenToken)! | ||
} | ||
|
||
/** | ||
* Get the location of the given function node for reporting. | ||
* @param node - The function node to get. | ||
* @param sourceCode - The source code object to get tokens. | ||
* @returns The location of the function node for reporting. | ||
*/ | ||
export function getFunctionHeadLocation( | ||
node: ESTree.Function, | ||
sourceCode: SourceCode, | ||
): ESTree.SourceLocation { | ||
const parent = getParent(node)! | ||
let start: ESTree.Position | null = null | ||
let end: ESTree.Position | null = null | ||
|
||
if (node.type === "ArrowFunctionExpression") { | ||
const arrowToken = sourceCode.getTokenBefore(node.body, isArrowToken)! | ||
|
||
start = arrowToken.loc.start | ||
end = arrowToken.loc.end | ||
} else if ( | ||
parent.type === "Property" || | ||
parent.type === "MethodDefinition" || | ||
parent.type === "PropertyDefinition" | ||
) { | ||
start = parent.loc!.start | ||
end = getOpeningParenOfParams(node, sourceCode).loc.start | ||
} else { | ||
start = node.loc!.start | ||
end = getOpeningParenOfParams(node, sourceCode).loc.start | ||
} | ||
|
||
return { | ||
start: { ...start }, | ||
end: { ...end }, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.