forked from mysticatea/eslint-plugin-node
-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: typescript (jsdoc) checking and definition generation (#169)
* chore: add some low hanging fruit types * chore: small steps * chore: Simplify check-existence * fix: All types in the utils directory * fix(prefer-promises): missing TraceMap type * fix(hashbang): Add missing types * fix: Add types for "process-exit-as-throw" * chore: unifi TraceMap * feat: Types for lib/rules * Update tsconfig.json Co-authored-by: Sebastian Good <2230835+scagood@users.noreply.github.com> * ci: Add tsc compile on pack and test * ci: Export types in package.json * ci: run tests and linting once * chore: Remove all "{Object}" from "@typedef" * fix: Remove typecast infavour of union a discriminator check * chore: Remove more unneed casting * fix: Better types from JSON.parse * chore: 1 typedef per doc comment * fix: dont cast ErrnoException * feat: better "TraceMap" types * chore: Add comment for the "ts-expect-error" --------- Co-authored-by: 唯然 <weiran.zsd@outlook.com>
- Loading branch information
1 parent
5e82d7f
commit 6d8ed14
Showing
133 changed files
with
2,801 additions
and
959 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
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,4 +5,6 @@ | |
/test.js | ||
.eslintcache | ||
.vscode | ||
.idea/ | ||
.idea/ | ||
|
||
types/ |
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,21 +1,19 @@ | ||
"use strict" | ||
|
||
module.exports = { | ||
commonRules: { | ||
"n/no-deprecated-api": "error", | ||
"n/no-extraneous-import": "error", | ||
"n/no-extraneous-require": "error", | ||
"n/no-exports-assign": "error", | ||
"n/no-missing-import": "error", | ||
"n/no-missing-require": "error", | ||
"n/no-process-exit": "error", | ||
"n/no-unpublished-bin": "error", | ||
"n/no-unpublished-import": "error", | ||
"n/no-unpublished-require": "error", | ||
"n/no-unsupported-features/es-builtins": "error", | ||
"n/no-unsupported-features/es-syntax": "error", | ||
"n/no-unsupported-features/node-builtins": "error", | ||
"n/process-exit-as-throw": "error", | ||
"n/hashbang": "error", | ||
}, | ||
} | ||
module.exports.commonRules = /** @type {const} */ ({ | ||
"n/no-deprecated-api": "error", | ||
"n/no-extraneous-import": "error", | ||
"n/no-extraneous-require": "error", | ||
"n/no-exports-assign": "error", | ||
"n/no-missing-import": "error", | ||
"n/no-missing-require": "error", | ||
"n/no-process-exit": "error", | ||
"n/no-unpublished-bin": "error", | ||
"n/no-unpublished-import": "error", | ||
"n/no-unpublished-require": "error", | ||
"n/no-unsupported-features/es-builtins": "error", | ||
"n/no-unsupported-features/es-syntax": "error", | ||
"n/no-unsupported-features/node-builtins": "error", | ||
"n/process-exit-as-throw": "error", | ||
"n/hashbang": "error", | ||
}) |
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
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,80 @@ | ||
declare module "eslint-plugin-es-x" { | ||
export const rules: NonNullable<import('eslint').ESLint.Plugin["rules"]>; | ||
} | ||
|
||
declare module "@eslint-community/eslint-utils" { | ||
import * as estree from 'estree'; | ||
import * as eslint from 'eslint'; | ||
|
||
type Node = estree.Node | estree.Expression; | ||
|
||
export const READ: unique symbol; | ||
export const CALL: unique symbol; | ||
export const CONSTRUCT: unique symbol; | ||
export const ESM: unique symbol; | ||
export class ReferenceTracker { | ||
constructor(globalScope: eslint.Scope.Scope, { mode, globalObjectNames, }?: { | ||
mode?: "legacy" | "strict" | undefined; | ||
globalObjectNames?: string[] | undefined; | ||
} | undefined); | ||
variableStack: eslint.Scope.Variable[]; | ||
globalScope: eslint.Scope.Scope; | ||
mode: "legacy" | "strict"; | ||
globalObjectNames: string[]; | ||
iterateGlobalReferences<Info extends unknown>(traceMap: TraceMap<Info>): IterableIterator<Reference<Info>>; | ||
iterateCjsReferences<Info extends unknown>(traceMap: TraceMap<Info>): IterableIterator<Reference<Info>>; | ||
iterateEsmReferences<Info extends unknown>(traceMap: TraceMap<Info>): IterableIterator<Reference<Info>>; | ||
} | ||
export namespace ReferenceTracker { | ||
export { READ }; | ||
export { CALL }; | ||
export { CONSTRUCT }; | ||
export { ESM }; | ||
} | ||
type ReferenceType = typeof READ | typeof CALL | typeof CONSTRUCT; | ||
type TraceMap<Info extends unknown> = { | ||
[READ]?: Info; | ||
[CALL]?: Info; | ||
[CONSTRUCT]?: Info; | ||
[key: string]: TraceMap<Info>; | ||
} | ||
type RichNode = eslint.Rule.Node | Node; | ||
type Reference<Info extends unknown> = { | ||
node: RichNode; | ||
path: string[]; | ||
type: ReferenceType; | ||
info: Info; | ||
}; | ||
|
||
export function findVariable(initialScope: eslint.Scope.Scope, nameOrNode: string | Node): eslint.Scope.Variable | null; | ||
|
||
export function getFunctionHeadLocation(node: Extract<eslint.Rule.Node, { | ||
type: 'FunctionDeclaration' | 'FunctionExpression' | 'ArrowFunctionExpression'; | ||
}>, sourceCode: eslint.SourceCode): eslint.AST.SourceLocation | null; | ||
|
||
export function getFunctionNameWithKind(node: Extract<eslint.Rule.Node, { | ||
type: 'FunctionDeclaration' | 'FunctionExpression' | 'ArrowFunctionExpression'; | ||
}>, sourceCode?: eslint.SourceCode | undefined): string; | ||
|
||
export function getInnermostScope(initialScope: eslint.Scope.Scope, node: Node): eslint.Scope.Scope; | ||
|
||
export function getPropertyName(node: Extract<Node, { | ||
type: 'MemberExpression' | 'Property' | 'MethodDefinition' | 'PropertyDefinition'; | ||
}>, initialScope?: eslint.Scope.Scope | undefined): string | null; | ||
|
||
export function getStaticValue(node: Node, initialScope?: eslint.Scope.Scope | null | undefined): { | ||
value: unknown; | ||
optional?: never; | ||
} | { | ||
value: undefined; | ||
optional?: true; | ||
} | null; | ||
|
||
export function getStringIfConstant(node: Node, initialScope?: eslint.Scope.Scope | null | undefined): string | null; | ||
|
||
export function hasSideEffect(node: eslint.Rule.Node, sourceCode: eslint.SourceCode, { considerGetters, considerImplicitTypeConversion }?: VisitOptions | undefined): boolean; | ||
type VisitOptions = { | ||
considerGetters?: boolean | undefined; | ||
considerImplicitTypeConversion?: boolean | undefined; | ||
}; | ||
} |
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.