Skip to content

Commit 7bcda76

Browse files
nzakasmdjermanovic
andauthored
refactor: Add type references (#18652)
* refactor: Add type references * Update lib/languages/js/index.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> --------- Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
1 parent 51bf57c commit 7bcda76

File tree

6 files changed

+37
-11
lines changed

6 files changed

+37
-11
lines changed

lib/languages/js/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ const { validateLanguageOptions } = require("./validate-language-options");
2020
// Type Definitions
2121
//-----------------------------------------------------------------------------
2222

23-
/** @typedef {import("../../linter/vfile").VFile} VFile */
23+
/** @typedef {import("@eslint/core").File} File */
24+
/** @typedef {import("@eslint/core").Language} Language */
25+
/** @typedef {import("@eslint/core").OkParseResult} OkParseResult */
2426

2527
//-----------------------------------------------------------------------------
2628
// Helpers
@@ -56,6 +58,9 @@ function analyzeScope(ast, languageOptions, visitorKeys) {
5658
// Exports
5759
//-----------------------------------------------------------------------------
5860

61+
/**
62+
* @type {Language}
63+
*/
5964
module.exports = {
6065

6166
fileType: "text",
@@ -143,7 +148,7 @@ module.exports = {
143148

144149
/**
145150
* Parses the given file into an AST.
146-
* @param {VFile} file The virtual file to parse.
151+
* @param {File} file The virtual file to parse.
147152
* @param {Object} options Additional options passed from ESLint.
148153
* @param {LanguageOptions} options.languageOptions The language options.
149154
* @returns {Object} The result of parsing.
@@ -218,8 +223,8 @@ module.exports = {
218223

219224
/**
220225
* Creates a new `SourceCode` object from the given information.
221-
* @param {VFile} file The virtual file to create a `SourceCode` object from.
222-
* @param {Object} parseResult The result returned from `parse()`.
226+
* @param {File} file The virtual file to create a `SourceCode` object from.
227+
* @param {OkParseResult} parseResult The result returned from `parse()`.
223228
* @param {Object} options Additional options passed from ESLint.
224229
* @param {LanguageOptions} options.languageOptions The language options.
225230
* @returns {SourceCode} The new `SourceCode` object.

lib/languages/js/source-code/source-code.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ const
2929
//------------------------------------------------------------------------------
3030

3131
/** @typedef {import("eslint-scope").Variable} Variable */
32+
/** @typedef {import("eslint-scope").Scope} Scope */
33+
/** @typedef {import("@eslint/core").SourceCode} ISourceCode */
34+
/** @typedef {import("@eslint/core").Directive} IDirective */
35+
/** @typedef {import("@eslint/core").TraversalStep} ITraversalStep */
3236

3337
//------------------------------------------------------------------------------
3438
// Private
@@ -373,6 +377,7 @@ class TraversalStep {
373377

374378
/**
375379
* A class to represent a directive comment.
380+
* @implements {IDirective}
376381
*/
377382
class Directive {
378383

@@ -429,12 +434,13 @@ const caches = Symbol("caches");
429434

430435
/**
431436
* Represents parsed source code.
437+
* @implements {ISourceCode}
432438
*/
433439
class SourceCode extends TokenStore {
434440

435441
/**
436442
* The cache of steps that were taken while traversing the source code.
437-
* @type {Array<TraversalStep>}
443+
* @type {Array<ITraversalStep>}
438444
*/
439445
#steps;
440446

@@ -838,7 +844,7 @@ class SourceCode extends TokenStore {
838844
/**
839845
* Gets the scope for the given node
840846
* @param {ASTNode} currentNode The node to get the scope of
841-
* @returns {eslint-scope.Scope} The scope information for this node
847+
* @returns {Scope} The scope information for this node
842848
* @throws {TypeError} If the `currentNode` argument is missing.
843849
*/
844850
getScope(currentNode) {

lib/linter/apply-disable-directives.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
//------------------------------------------------------------------------------
1111

1212
/** @typedef {import("../shared/types").LintMessage} LintMessage */
13+
/** @typedef {import("@eslint/core").Language} Language */
14+
/** @typedef {import("@eslint/core").Position} Position */
15+
/** @typedef {import("@eslint/core").RulesConfig} RulesConfig */
1316

1417
//------------------------------------------------------------------------------
1518
// Module Definition
@@ -24,8 +27,8 @@ const {
2427

2528
/**
2629
* Compares the locations of two objects in a source file
27-
* @param {{line: number, column: number}} itemA The first object
28-
* @param {{line: number, column: number}} itemB The second object
30+
* @param {Position} itemA The first object
31+
* @param {Position} itemB The second object
2932
* @returns {number} A value less than 1 if itemA appears before itemB in the source file, greater than 1 if
3033
* itemA appears after itemB in the source file, or 0 if itemA and itemB have the same location.
3134
*/
@@ -418,7 +421,7 @@ function applyDirectives(options) {
418421
* @param {{ruleId: (string|null), line: number, column: number}[]} options.problems
419422
* A list of problems reported by rules, sorted by increasing location in the file, with one-based columns.
420423
* @param {"off" | "warn" | "error"} options.reportUnusedDisableDirectives If `"warn"` or `"error"`, adds additional problems for unused directives
421-
* @param {Object} options.configuredRules The rules configuration.
424+
* @param {RulesConfig} options.configuredRules The rules configuration.
422425
* @param {Function} options.ruleFilter A predicate function to filter which rules should be executed.
423426
* @param {boolean} options.disableFixes If true, it doesn't make `fix` properties.
424427
* @returns {{ruleId: (string|null), line: number, column: number, suppressions?: {kind: string, justification: string}}[]}

lib/linter/linter.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ const STEP_KIND_CALL = 2;
7272
/** @typedef {import("../shared/types").Processor} Processor */
7373
/** @typedef {import("../shared/types").Rule} Rule */
7474
/** @typedef {import("../shared/types").Times} Times */
75+
/** @typedef {import("@eslint/core").Language} Language */
76+
/** @typedef {import("@eslint/core").RuleSeverity} RuleSeverity */
77+
/** @typedef {import("@eslint/core").RuleConfig} RuleConfig */
78+
7579

7680
/* eslint-disable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/4#issuecomment-778805577 */
7781
/**
@@ -276,7 +280,7 @@ function updateLocationInformation({ line, column, endLine, endColumn }, languag
276280
* @param {string} [options.ruleId] the ruleId to report
277281
* @param {Object} [options.loc] the loc to report
278282
* @param {string} [options.message] the error message to report
279-
* @param {string} [options.severity] the error message to report
283+
* @param {RuleSeverity} [options.severity] the error message to report
280284
* @param {Language} [options.language] the language to use to adjust the location information
281285
* @returns {LintMessage} created problem, returns a missing-rule problem if only provided ruleId.
282286
* @private
@@ -877,7 +881,7 @@ function storeTime(time, timeOpts, slots) {
877881

878882
/**
879883
* Get the options for a rule (not including severity), if any
880-
* @param {Array|number} ruleConfig rule configuration
884+
* @param {RuleConfig} ruleConfig rule configuration
881885
* @returns {Array} of rule options, empty Array if none
882886
*/
883887
function getRuleOptions(ruleConfig) {

lib/linter/vfile.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
"use strict";
77

8+
//-----------------------------------------------------------------------------
9+
// Type Definitions
10+
//-----------------------------------------------------------------------------
11+
12+
/** @typedef {import("@eslint/core").File} File */
13+
814
//------------------------------------------------------------------------------
915
// Helpers
1016
//------------------------------------------------------------------------------
@@ -54,6 +60,7 @@ function stripUnicodeBOM(value) {
5460

5561
/**
5662
* Represents a virtual file inside of ESLint.
63+
* @implements {File}
5764
*/
5865
class VFile {
5966

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"devDependencies": {
105105
"@babel/core": "^7.4.3",
106106
"@babel/preset-env": "^7.4.3",
107+
"@eslint/core": "^0.1.0",
107108
"@types/estree": "^1.0.5",
108109
"@types/node": "^20.11.5",
109110
"@wdio/browser-runner": "^8.38.3",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy