Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@eslint/core

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eslint/core - npm Package Compare versions

Comparing version 0.7.0 to 0.8.0

419

dist/esm/types.d.ts
/**
* @fileoverview Shared types for ESLint Core.
*/
import { JSONSchema4 } from "json-schema";
/**

@@ -23,9 +24,2 @@ * Represents an error inside of a file.

/**
* Represents an AST node or token with location information in ESLint format.
*/
export interface SyntaxElement {
loc: SourceLocation;
range: SourceRange;
}
/**
* Represents the start and end coordinates of a node inside the source.

@@ -63,2 +57,327 @@ */

/**
* What the rule is responsible for finding:
* - `problem` means the rule has noticed a potential error.
* - `suggestion` means the rule suggests an alternate or better approach.
* - `layout` means the rule is looking at spacing, indentation, etc.
*/
export type RuleType = "problem" | "suggestion" | "layout";
/**
* The type of fix the rule can provide:
* - `code` means the rule can fix syntax.
* - `whitespace` means the rule can fix spacing and indentation.
*/
export type RuleFixType = "code" | "whitespace";
/**
* An object containing visitor information for a rule. Each method is either the
* name of a node type or a selector, or is a method that will be called at specific
* times during the traversal.
*/
export interface RuleVisitor {
/**
* Called for each node in the AST or at specific times during the traversal.
*/
[key: string]: (...args: any[]) => void;
}
/**
* Rule meta information used for documentation.
*/
export interface RulesMetaDocs {
/**
* A short description of the rule.
*/
description?: string | undefined;
/**
* The URL to the documentation for the rule.
*/
url?: string | undefined;
/**
* The category the rule falls under.
* @deprecated No longer used.
*/
category?: string | undefined;
/**
* Indicates if the rule is generally recommended for all users.
*/
recommended?: boolean | undefined;
}
/**
* Meta information about a rule.
*/
export interface RulesMeta<MessageIds extends string = string, ExtRuleDocs = unknown> {
/**
* Properties that are used when documenting the rule.
*/
docs?: (RulesMetaDocs & ExtRuleDocs) | undefined;
/**
* The type of rule.
*/
type?: RuleType | undefined;
/**
* The schema for the rule options. Required if the rule has options.
*/
schema?: JSONSchema4 | JSONSchema4[] | false | undefined;
/**
* The messages that the rule can report.
*/
messages?: Record<MessageIds, string>;
/**
* The deprecated rules for the rule.
*/
deprecated?: boolean | undefined;
/**
* When a rule is deprecated, indicates the rule ID(s) that should be used instead.
*/
replacedBy?: string[] | undefined;
/**
* Indicates if the rule is fixable, and if so, what type of fix it provides.
*/
fixable?: RuleFixType | undefined;
/**
* Indicates if the rule may provide suggestions.
*/
hasSuggestions?: boolean | undefined;
}
/**
* Generic type for `RuleContext`.
*/
export interface RuleContextTypeOptions {
LangOptions?: LanguageOptions;
Code?: SourceCode;
RuleOptions?: unknown[];
Node?: unknown;
}
/**
* Represents the context object that is passed to a rule. This object contains
* information about the current state of the linting process and is the rule's
* view into the outside world.
*/
export interface RuleContext<Options extends RuleContextTypeOptions = {
LangOptions: LanguageOptions;
Code: SourceCode;
RuleOptions: unknown[];
Node: unknown;
}> {
/**
* The current working directory for the session.
*/
cwd: string;
/**
* Returns the current working directory for the session.
* @deprecated Use `cwd` instead.
*/
getCwd(): string;
/**
* The filename of the file being linted.
*/
filename: string;
/**
* Returns the filename of the file being linted.
* @deprecated Use `filename` instead.
*/
getFilename(): string;
/**
* The physical filename of the file being linted.
*/
physicalFilename: string;
/**
* Returns the physical filename of the file being linted.
* @deprecated Use `physicalFilename` instead.
*/
getPhysicalFilename(): string;
/**
* The source code object that the rule is running on.
*/
sourceCode: Options["Code"];
/**
* Returns the source code object that the rule is running on.
* @deprecated Use `sourceCode` instead.
*/
getSourceCode(): Options["Code"];
/**
* Shared settings for the configuration.
*/
settings: SettingsConfig;
/**
* Parser-specific options for the configuration.
* @deprecated Use `languageOptions.parserOptions` instead.
*/
parserOptions: Record<string, unknown>;
/**
* The language options for the configuration.
*/
languageOptions: Options["LangOptions"];
/**
* The CommonJS path to the parser used while parsing this file.
* @deprecated No longer used.
*/
parserPath: string | undefined;
/**
* The rule ID.
*/
id: string;
/**
* The rule's configured options.
*/
options: Options["RuleOptions"];
/**
* The report function that the rule should use to report problems.
* @param violation The violation to report.
*/
report(violation: ViolationReport<Options["Node"]>): void;
}
/**
* Manager of text edits for a rule fix.
*/
export interface RuleTextEditor<EditableSyntaxElement = unknown> {
/**
* Inserts text after the specified node or token.
* @param syntaxElement The node or token to insert after.
* @param text The edit to insert after the node or token.
*/
insertTextAfter(syntaxElement: EditableSyntaxElement, text: string): RuleTextEdit;
/**
* Inserts text after the specified range.
* @param range The range to insert after.
* @param text The edit to insert after the range.
*/
insertTextAfterRange(range: SourceRange, text: string): RuleTextEdit;
/**
* Inserts text before the specified node or token.
* @param syntaxElement A syntax element with location information to insert before.
* @param text The edit to insert before the node or token.
*/
insertTextBefore(syntaxElement: EditableSyntaxElement, text: string): RuleTextEdit;
/**
* Inserts text before the specified range.
* @param range The range to insert before.
* @param text The edit to insert before the range.
*/
insertTextBeforeRange(range: SourceRange, text: string): RuleTextEdit;
/**
* Removes the specified node or token.
* @param syntaxElement A syntax element with location information to remove.
* @returns The edit to remove the node or token.
*/
remove(syntaxElement: EditableSyntaxElement): RuleTextEdit;
/**
* Removes the specified range.
* @param range The range to remove.
* @returns The edit to remove the range.
*/
removeRange(range: SourceRange): RuleTextEdit;
/**
* Replaces the specified node or token with the given text.
* @param syntaxElement A syntax element with location information to replace.
* @param text The text to replace the node or token with.
* @returns The edit to replace the node or token.
*/
replaceText(syntaxElement: EditableSyntaxElement, text: string): RuleTextEdit;
/**
* Replaces the specified range with the given text.
* @param range The range to replace.
* @param text The text to replace the range with.
* @returns The edit to replace the range.
*/
replaceTextRange(range: SourceRange, text: string): RuleTextEdit;
}
/**
* Represents a fix for a rule violation implemented as a text edit.
*/
export interface RuleTextEdit {
/**
* The range to replace.
*/
range: SourceRange;
/**
* The text to insert.
*/
text: string;
}
interface ViolationReportBase {
/**
* The type of node that the violation is for.
* @deprecated May be removed in the future.
*/
nodeType?: string | undefined;
/**
* The data to insert into the message.
*/
data?: Record<string, string> | undefined;
/**
* The fix to be applied for the violation.
* @param fixer The text editor to apply the fix.
* @returns The fix(es) for the violation.
*/
fix?(fixer: RuleTextEditor): RuleTextEdit | Iterable<RuleTextEdit> | null;
/**
* An array of suggested fixes for the problem. These fixes may change the
* behavior of the code, so they are not applied automatically.
*/
suggest?: SuggestedEdit[];
}
type ViolationMessage = {
message: string;
} | {
messageId: string;
};
type ViolationLocation<Node> = {
loc: SourceLocation;
} | {
node: Node;
};
export type ViolationReport<Node = unknown> = ViolationReportBase & ViolationMessage & ViolationLocation<Node>;
interface SuggestedEditBase {
/**
* The data to insert into the message.
*/
data?: Record<string, string> | undefined;
/**
* The fix to be applied for the suggestion.
* @param fixer The text editor to apply the fix.
* @returns The fix for the suggestion.
*/
fix?(fixer: RuleTextEditor): RuleTextEdit | Iterable<RuleTextEdit> | null;
}
type SuggestionMessage = {
desc: string;
} | {
messageId: string;
};
/**
* A suggested edit for a rule violation.
*/
export type SuggestedEdit = SuggestedEditBase & SuggestionMessage;
/**
* Generic options for the `RuleDefinition` type.
*/
export interface RuleDefinitionTypeOptions {
LangOptions?: LanguageOptions;
Code?: SourceCode;
RuleOptions?: unknown[];
Visitor?: RuleVisitor;
Node?: unknown;
MessageIds?: string;
ExtRuleDocs?: unknown;
}
/**
* The definition of an ESLint rule.
*/
export interface RuleDefinition<Options extends RuleDefinitionTypeOptions> {
/**
* The meta information for the rule.
*/
meta?: RulesMeta<Options["MessageIds"], Options["ExtRuleDocs"]>;
/**
* Creates the visitor that ESLint uses to apply the rule during traversal.
* @param context The rule context.
* @returns The rule visitor.
*/
create(context: RuleContext<{
LangOptions: Options["LangOptions"];
Code: Options["Code"];
RuleOptions: Options["RuleOptions"];
Node: Options["Node"];
}>): Options["Visitor"];
}
/**
* The human readable severity level used in a configuration.

@@ -73,3 +392,2 @@ */

* - `2` means error.
*
*/

@@ -107,5 +425,19 @@ export type SeverityLevel = 0 | 1 | 2;

/**
* Generic options for the `Language` type.
*/
export interface LanguageTypeOptions {
LangOptions?: LanguageOptions;
Code?: SourceCode;
RootNode?: unknown;
Node: unknown;
}
/**
* Represents a plugin language.
*/
export interface Language {
export interface Language<Options extends LanguageTypeOptions = {
LangOptions: LanguageOptions;
Code: SourceCode;
RootNode: unknown;
Node: unknown;
}> {
/**

@@ -138,3 +470,3 @@ * Indicates how ESLint should read the file.

*/
validateLanguageOptions(languageOptions: LanguageOptions): void;
validateLanguageOptions(languageOptions: Options["LangOptions"]): void;
/**

@@ -146,3 +478,3 @@ * Helper for esquery that allows languages to match nodes against

*/
matchesSelectorClass?(className: string, node: object, ancestry: object[]): boolean;
matchesSelectorClass?(className: string, node: Options["Node"], ancestry: Options["Node"][]): boolean;
/**

@@ -153,7 +485,7 @@ * Parses the given file input into its component parts. This file should not

*/
parse(file: File, context: LanguageContext): ParseResult;
parse(file: File, context: LanguageContext<Options["LangOptions"]>): ParseResult<Options["RootNode"]>;
/**
* Creates SourceCode object that ESLint uses to work with a file.
*/
createSourceCode(file: File, input: OkParseResult, context: LanguageContext): SourceCode;
createSourceCode(file: File, input: OkParseResult<Options["RootNode"]>, context: LanguageContext<Options["LangOptions"]>): Options["Code"];
}

@@ -167,4 +499,4 @@ /**

*/
export interface LanguageContext {
languageOptions: LanguageOptions;
export interface LanguageContext<LangOptions = LanguageOptions> {
languageOptions: LangOptions;
}

@@ -199,3 +531,3 @@ /**

*/
export interface OkParseResult<T extends object = object> {
export interface OkParseResult<RootNode = unknown> {
/**

@@ -211,3 +543,3 @@ * Indicates if the parse was successful. If true, the parse was successful

*/
ast: T;
ast: RootNode;
/**

@@ -238,3 +570,3 @@ * Any additional data that the parser wants to provide.

}
export type ParseResult<T extends object = object> = OkParseResult<T> | NotOkParseResult;
export type ParseResult<RootNode = unknown> = OkParseResult<RootNode> | NotOkParseResult;
/**

@@ -256,9 +588,23 @@ * Represents inline configuration found in the source code.

/**
* Generic options for the `SourceCodeBase` type.
*/
interface SourceCodeBaseTypeOptions {
LangOptions?: LanguageOptions;
RootNode?: unknown;
SyntaxElementWithLoc?: unknown;
ConfigNode?: unknown;
}
/**
* Represents the basic interface for a source code object.
*/
interface SourceCodeBase {
interface SourceCodeBase<Options extends SourceCodeBaseTypeOptions = {
LangOptions: LanguageOptions;
RootNode: unknown;
SyntaxElementWithLoc: unknown;
ConfigNode: unknown;
}> {
/**
* Root of the AST.
*/
ast: object;
ast: Options["RootNode"];
/**

@@ -272,8 +618,12 @@ * The traversal path that tools should take when evaluating the AST.

* Retrieves the equivalent of `loc` for a given node or token.
* @param syntaxElement The node or token to get the location for.
* @returns The location of the node or token.
*/
getLoc(nodeOrToken: object): SourceLocation;
getLoc(syntaxElement: Options["SyntaxElementWithLoc"]): SourceLocation;
/**
* Retrieves the equivalent of `range` for a given node or token.
* @param syntaxElement The node or token to get the range for.
* @returns The range of the node or token.
*/
getRange(nodeOrToken: object): SourceRange;
getRange(syntaxElement: Options["SyntaxElementWithLoc"]): SourceRange;
/**

@@ -286,3 +636,3 @@ * Traversal of AST.

*/
applyLanguageOptions?(languageOptions: LanguageOptions): void;
applyLanguageOptions?(languageOptions: Options["LangOptions"]): void;
/**

@@ -300,3 +650,3 @@ * Return all of the inline areas where ESLint should be disabled/enabled

*/
getInlineConfigNodes?(): object[];
getInlineConfigNodes?(): Options["ConfigNode"][];
/**

@@ -321,3 +671,8 @@ * Applies configuration found inside of the source code. This method is only

*/
export interface TextSourceCode extends SourceCodeBase {
export interface TextSourceCode<Options extends SourceCodeBaseTypeOptions = {
LangOptions: LanguageOptions;
RootNode: unknown;
SyntaxElementWithLoc: unknown;
ConfigNode: unknown;
}> extends SourceCodeBase<Options> {
/**

@@ -331,3 +686,8 @@ * The body of the file that you'd like rule developers to access.

*/
export interface BinarySourceCode extends SourceCodeBase {
export interface BinarySourceCode<Options extends SourceCodeBaseTypeOptions = {
LangOptions: LanguageOptions;
RootNode: unknown;
SyntaxElementWithLoc: unknown;
ConfigNode: unknown;
}> extends SourceCodeBase<Options> {
/**

@@ -338,3 +698,8 @@ * The body of the file that you'd like rule developers to access.

}
export type SourceCode = TextSourceCode | BinarySourceCode;
export type SourceCode<Options extends SourceCodeBaseTypeOptions = {
LangOptions: LanguageOptions;
RootNode: unknown;
SyntaxElementWithLoc: unknown;
ConfigNode: unknown;
}> = TextSourceCode<Options> | BinarySourceCode<Options>;
/**

@@ -341,0 +706,0 @@ * Represents a traversal step visiting the AST.

3

package.json
{
"name": "@eslint/core",
"version": "0.7.0",
"version": "0.8.0",
"description": "Runtime-agnostic core of ESLint",

@@ -39,2 +39,3 @@ "type": "module",

"devDependencies": {
"json-schema": "^0.4.0",
"typescript": "^5.4.5"

@@ -41,0 +42,0 @@ },

@@ -25,3 +25,3 @@ # ESLint Core

<p><a href="https://www.jetbrains.com/"><img src="https://images.opencollective.com/jetbrains/fe76f99/logo.png" alt="JetBrains" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301?v=4" alt="American Express" height="64"></a> <a href="https://www.workleap.com"><img src="https://avatars.githubusercontent.com/u/53535748?u=d1e55d7661d724bf2281c1bfd33cb8f99fe2465f&v=4" alt="Workleap" height="64"></a></p><h3>Bronze Sponsors</h3>
<p><a href="https://www.wordhint.net/"><img src="https://images.opencollective.com/wordhint/be86813/avatar.png" alt="WordHint" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340?v=4" alt="GitBook" height="32"></a> <a href="https://nx.dev"><img src="https://avatars.githubusercontent.com/u/23692104?v=4" alt="Nx" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774?v=4" alt="HeroCoders" height="32"></a> <a href="https://usenextbase.com"><img src="https://avatars.githubusercontent.com/u/145838380?v=4" alt="Nextbase Starter Kit" height="32"></a></p>
<p><a href="https://www.wordhint.net/"><img src="https://images.opencollective.com/wordhint/be86813/avatar.png" alt="WordHint" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340?v=4" alt="GitBook" height="32"></a> <a href="https://nx.dev"><img src="https://avatars.githubusercontent.com/u/23692104?v=4" alt="Nx" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774?v=4" alt="HeroCoders" height="32"></a></p>
<h3>Technology Sponsors</h3>

@@ -28,0 +28,0 @@ Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc