Skip to content

Commit

Permalink
chore: use jsDoc import tag
Browse files Browse the repository at this point in the history
  • Loading branch information
mainframev committed Dec 23, 2024
1 parent 94725b7 commit 415da9a
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 83 deletions.
13 changes: 8 additions & 5 deletions packages/eslint-plugin/src/rules/ban-context-export/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ const minimatch = require('minimatch');
const createRule = require('../../utils/createRule');
const { getTypeServices } = require('../../utils/type-services');

/** @typedef { import('@typescript-eslint/utils').TSESTree.VariableDeclarator } VariableDeclarator*/
/** @typedef { import('@typescript-eslint/utils').TSESTree.ExportSpecifier} ExportSpecifier */
/**
* @import { TSESTree } from '@typescript-eslint/utils'
* @import { Type } from "typescript"
*/

/**
* @typedef {{
* exclude?: string[];
Expand Down Expand Up @@ -45,8 +48,8 @@ module.exports = createRule({
const [{ exclude = /** @type string[]*/ ([]) } = {}] = context.options;

/**
* @param { ExportSpecifier | VariableDeclarator } node
* @param {string} exportName
* @param { TSESTree.ExportSpecifier | TSESTree.VariableDeclarator } node
* @param { string } exportName
*/
function checkContextType(node, exportName) {
const currentFileName = context.filename;
Expand All @@ -73,7 +76,7 @@ module.exports = createRule({
* - `createContext` from `@fluentui/react-context-selector` return type is `type Context` we use `aliasSymbol`
*
* @see https://github.com/microsoft/TypeScript/issues/46921#issuecomment-985048637
* @typedef {Extract<keyof import('typescript').Type, 'symbol' | 'aliasSymbol'>} TypeProperty
* @typedef {Extract<keyof Type, 'symbol' | 'aliasSymbol'>} TypeProperty
*/

/**
Expand Down
17 changes: 6 additions & 11 deletions packages/eslint-plugin/src/rules/ban-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
const { AST_NODE_TYPES } = require('@typescript-eslint/utils');
const createRule = require('../utils/createRule');

// Nasty syntax required for type imports until https://github.com/microsoft/TypeScript/issues/22160 is implemented.
// For some reason just importing TSESTree and accessing properties off that doesn't work.
/**
* @typedef {import("@typescript-eslint/utils").TSESTree.ExportNamedDeclaration} ExportNamedDeclaration
* @typedef {import("@typescript-eslint/utils").TSESTree.ExportSpecifier} ExportSpecifier
* @typedef {import("@typescript-eslint/utils").TSESTree.Identifier} Identifier
* @typedef {import("@typescript-eslint/utils").TSESTree.ImportDeclaration} ImportDeclaration
* @typedef {import("@typescript-eslint/utils").TSESTree.ImportSpecifier} ImportSpecifier
*
* @import { TSESTree } from '@typescript-eslint/utils'; */

/**
* @typedef {{
* path?: string;
* pathRegex?: string;
Expand Down Expand Up @@ -104,9 +99,9 @@ module.exports = createRule({
}

/**
* @param {ImportDeclaration | ExportNamedDeclaration} importOrExport the whole import/export node
* @param {TSESTree.ImportDeclaration | TSESTree.ExportNamedDeclaration} importOrExport the whole import/export node
* @param {string} importPath path importing/exporting from
* @param {Identifier[]} identifiers imported/exported identifiers
* @param {TSESTree.Identifier[]} identifiers imported/exported identifiers
*/
function checkImportOrExport(importOrExport, importPath, identifiers) {
for (const rule of options) {
Expand Down Expand Up @@ -152,7 +147,7 @@ module.exports = createRule({
return;
}

const specifiers = /** @type {ImportSpecifier[]} */ (
const specifiers = /** @type {TSESTree.ImportSpecifier[]} */ (
imprt.specifiers.filter(
// Filter out default imports and namespace (star) imports
spec => spec.type === AST_NODE_TYPES.ImportSpecifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { AST_NODE_TYPES } = require('@typescript-eslint/utils');
const createRule = require('../../utils/createRule');

/**
* @typedef {import('./types').HTMLElementConstructorName} HTMLElementConstructorName
* @import { HTMLElementConstructorName } from './types';
*/

module.exports = createRule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ const createRule = require('../utils/createRule');
const { ESLintUtils } = require('@typescript-eslint/utils');

/**
* @typedef { import('@typescript-eslint/utils').TSESLint.RuleMetaDataDocs} RuleMetaDataDocs
* @import { TSESLint } from "@typescript-eslint/utils"
* @import { TypeChecker } from "typescript"
*/

module.exports = createRule({
name: 'deprecated-keyboard-event-props',
meta: {
type: 'problem',
docs: /** @type {RuleMetaDataDocs} */ ({
docs: /** @type {TSESLint.RuleMetaDataDocs} */ ({
description: 'Forbid use of deprecated KeyboardEvent props "which" and "keyCode".',
requiresTypeChecking: true,
}),
Expand All @@ -25,7 +26,7 @@ module.exports = createRule({
const ts = require('typescript');

const { program, esTreeNodeToTSNodeMap } = ESLintUtils.getParserServices(context);
/** @type {import("typescript").TypeChecker | undefined} */
/** @type {TypeChecker | undefined} */
let typeChecker;

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
const { AST_NODE_TYPES } = require('@typescript-eslint/utils');
const createRule = require('../../utils/createRule');

/** @import { TSESTree } from "@typescript-eslint/utils" */

/**
*
* @typedef {{
Expand Down Expand Up @@ -43,7 +45,7 @@ module.exports = createRule({
const createContextParentIdentifiers = [];

/**
* @param {import("@typescript-eslint/utils").TSESTree.Expression} callee
* @param { TSESTree.Expression } callee
*/
function isCalleeCreateContext(callee) {
if (
Expand Down Expand Up @@ -97,8 +99,8 @@ module.exports = createRule({
});

/**
* @param {import("@typescript-eslint/utils").TSESTree.CallExpressionArgument} expression
* @returns {expression is import("@typescript-eslint/utils").TSESTree.Identifier}
* @param { TSESTree.CallExpressionArgument } expression
* @returns { expression is TSESTree.Identifier }
*/
function isArgumentNotUndefined(expression) {
return expression.type !== AST_NODE_TYPES.Identifier || expression.name !== 'undefined';
Expand Down
11 changes: 6 additions & 5 deletions packages/eslint-plugin/src/rules/no-restricted-imports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ const { AST_NODE_TYPES } = require('@typescript-eslint/utils');
const createRule = require('../../utils/createRule');

/**
* @typedef {import("@typescript-eslint/utils").TSESTree.ImportClause} ImportClause
* @typedef {import("@typescript-eslint/utils").TSESTree.ImportDeclaration} ImportDeclaration
* @import { TSESTree } from "@typescript-eslint/utils"
*
* Lookup for insertion point for new imports when moving a restricted import to a preferred import.
* @typedef {{[preferredPkgName: string] : ImportDeclaration}} FixMap
* @typedef {{[preferredPkgName: string] : TSESTree.ImportDeclaration}} FixMap
*
* @typedef {{
* forbidden: string[],
Expand Down Expand Up @@ -132,9 +131,11 @@ module.exports = createRule({
function getUpdatedImportStatement(fixMap, preferredImportForCurrentPkg) {
const isTypeImport = imprt.importKind === 'type';
const currentSpecifiers = fixMap[preferredImportForCurrentPkg].specifiers.map(
(/** @type {ImportClause} */ specifier) => specifier.local.name,
(/** @type {TSESTree.ImportClause} */ specifier) => specifier.local.name,
);
const specifiersToAdd = imprt.specifiers.map(
(/** @type {TSESTree.ImportClause} */ specifier) => specifier.local.name,
);
const specifiersToAdd = imprt.specifiers.map((/** @type {ImportClause} */ specifier) => specifier.local.name);
const combinedSpecifiers = currentSpecifiers.concat(specifiersToAdd).join(', ');

return `import${
Expand Down
32 changes: 8 additions & 24 deletions packages/eslint-plugin/src/rules/no-visibility-modifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,14 @@ const MemberNameType = {
};

/**
* @typedef {import('@typescript-eslint/utils').TSESTree.MethodDefinition} MethodDefinition
* @typedef {import('@typescript-eslint/utils').TSESTree.PropertyDefinition} PropertyDefinition
* @typedef {import('@typescript-eslint/utils').TSESTree.Property} Property
* @typedef {import('@typescript-eslint/utils').TSESTree.TSAbstractMethodDefinition} TSAbstractMethodDefinition
* @typedef {import('@typescript-eslint/utils').TSESTree.TSAbstractPropertyDefinition} TSAbstractPropertyDefinition
* @typedef {import('@typescript-eslint/utils').TSESTree.TSMethodSignature} TSMethodSignature
* @typedef {import('@typescript-eslint/utils').TSESTree.TSPropertySignature} TSProperySignature
* @typedef {import('@typescript-eslint/utils').TSESLint.SourceCode} SourceCode
*/

// Nasty syntax required for type imports until https://github.com/microsoft/TypeScript/issues/22160 is implemented.
// For some reason just importing TSESTree and accessing properties off that doesn't work.
/**
* @typedef {import("@typescript-eslint/utils").TSESTree.PropertyDefinition} ClassProperty
* @typedef {import("@typescript-eslint/utils").TSESTree.Identifier} Identifier
* @typedef {import("@typescript-eslint/utils").TSESTree.Node} Node
* @typedef {import("@typescript-eslint/utils").TSESTree.TSParameterProperty} ParameterProperty
* @import { TSESLint, TSESTree } from "@typescript-eslint/utils"
*/

/**
* Gets a string name representation of the name of the given MethodDefinition
* or PropertyDefinition node, with handling for computed property names.
* @param {MethodDefinition | PropertyDefinition | Property | TSAbstractMethodDefinition | TSAbstractPropertyDefinition | TSMethodSignature | TSProperySignature} member The node to get the name of.
* @param {SourceCode} sourceCode The source code object.
* @param {TSESTree.MethodDefinition | TSESTree.PropertyDefinition | TSESTree.Property | TSESTree.TSAbstractMethodDefinition | TSESTree.TSAbstractPropertyDefinition | TSESTree.TSMethodSignature | TSESTree.TSPropertySignature} member The node to get the name of.
* @param {TSESLint.SourceCode} sourceCode The source code object.
* @returns {{ type: number; name: string }} The name of the member.
*/

Expand Down Expand Up @@ -92,7 +76,7 @@ module.exports = createRule({
/**
* Generates the report for rule violations
* @param {string} nodeType
* @param {Node} node
* @param {TSESTree.Node} node
* @param {{ type: number; name: string } | string} nodeName
*/
function reportIssue(nodeType, node, nodeName) {
Expand All @@ -113,7 +97,7 @@ module.exports = createRule({

/**
* Checks if a method declaration has an accessibility modifier.
* @param {MethodDefinition} methodDefinition The node representing a MethodDefinition.
* @param {TSESTree.MethodDefinition} methodDefinition The node representing a MethodDefinition.
*/
function checkMethodAccessibilityModifier(methodDefinition) {
let nodeType = 'method definition';
Expand All @@ -133,7 +117,7 @@ module.exports = createRule({

/**
* Checks if property has an accessibility modifier.
* @param {ClassProperty} classProperty The node representing a ClassProperty.
* @param {TSESTree.PropertyDefinition} classProperty The node representing a ClassProperty.
*/
function checkPropertyAccessibilityModifier(classProperty) {
const nodeType = 'class property';
Expand All @@ -149,7 +133,7 @@ module.exports = createRule({

/**
* Checks that the parameter property has the desired accessibility modifiers set.
* @param {ParameterProperty} node The node representing a Parameter Property
* @param {TSESTree.ParameterProperty} node The node representing a Parameter Property
*/
function checkParameterPropertyAccessibilityModifier(node) {
const nodeType = 'parameter property';
Expand All @@ -167,7 +151,7 @@ module.exports = createRule({
node.parameter.type === AST_NODE_TYPES.Identifier
? node.parameter.name
: // has to be an Identifier or TSC will throw an error
/** @type {Identifier} */ (node.parameter.left).name;
/** @type {TSESTree.Identifier} */ (node.parameter.left).name;

if (node.accessibility) {
reportIssue(nodeType, node, nodeName);
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-plugin/src/utils/configHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const { readProjectConfiguration } = require('@nx/devkit');
/**
* @typedef {{root: string, name: string}} Options
* @typedef {{name: string, version: string, dependencies: {[key: string]: string}}} PackageJson
* @typedef {import("@nx/devkit").WorkspaceJsonConfiguration} WorkspaceJsonConfiguration
*/

// FIXME: this is not ok (to depend on nx packages within this plugin - redo)
Expand Down
4 changes: 3 additions & 1 deletion packages/eslint-plugin/src/utils/type-services.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const { ESLintUtils } = require('@typescript-eslint/utils');

/** @import {TSESLint} from '@typescript-eslint/utils' */

/**
* @template {string} TMessageIds
* @template {unknown[]} TOptions
* @param {import('@typescript-eslint/utils').TSESLint.RuleContext<TMessageIds, Readonly<TOptions>>} context
* @param {TSESLint.RuleContext<TMessageIds, Readonly<TOptions>>} context
* @returns
*/
function getTypeServices(context) {
Expand Down
6 changes: 4 additions & 2 deletions scripts/babel/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* This files is used solely for react-northstar projects. Please don't any new logic here
*/

/** @typedef {import('@babel/core').TransformOptions['caller']} Caller */
/** @import {TransformOptions, ConfigAPI} from '@babel/core';
*/
/** @typedef {TransformOptions['caller']} Caller */

const isNodeCaller = (/** @type {Caller}*/ caller) => {
return Boolean(caller && (caller.name === '@babel/register' || caller.name === 'babel-jest'));
Expand All @@ -15,7 +17,7 @@ const supportsESM = (/** @type {Caller}*/ caller) => {
return !!((caller && caller.name === 'babel-loader') || caller.useESModules);
};

module.exports = (/** @type {import('@babel/core').ConfigAPI} */ api) => {
module.exports = (/** @type {ConfigAPI} */ api) => {
const isDistBundle = api.caller(isDistCaller);
const isNode = api.caller(isNodeCaller);
const useESModules = !isNode && api.caller(supportsESM);
Expand Down
14 changes: 9 additions & 5 deletions scripts/monorepo/src/getDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const fs = require('node:fs');

const { createProjectGraphAsync, joinPathFragments, workspaceRoot } = require('@nx/devkit');

/** @import { PackageJson } from './types';
* @import { ProjectGraph } from '@nx/devkit';
*/

/**
* @typedef {{
name: string,
Expand All @@ -10,7 +14,7 @@ const { createProjectGraphAsync, joinPathFragments, workspaceRoot } = require('@
}} Dependency
*/

/** @typedef {import('./types').PackageJson & {absoluteRootPath:string}} PackageJsonInfoData */
/** @typedef {PackageJson & {absoluteRootPath:string}} PackageJsonInfoData */

/**
* @type {Record<string,PackageJsonInfoData>}
Expand All @@ -20,7 +24,7 @@ const packageJsonInfo = {};
/**
*
* @param {string} project
* @param {import('@nx/devkit').ProjectGraph} projectGraph
* @param {ProjectGraph} projectGraph
*/
function getProjectPackageJsonInfo(project, projectGraph) {
const normalizedProjectName = getNormalizedName(project);
Expand Down Expand Up @@ -48,7 +52,7 @@ function getProjectPackageJsonInfo(project, projectGraph) {
/**
* Returns local dependencies of provided project. Local means dependency from within workspace
* @param {string} project
* @param {import('@nx/devkit').ProjectGraph} projectGraph
* @param {ProjectGraph} projectGraph
*/
function getLocalDeps(project, projectGraph) {
const deps = projectGraph.dependencies[project];
Expand All @@ -74,7 +78,7 @@ function getLocalDeps(project, projectGraph) {
/**
*
* @param {string} pkgName
* @param {import('./types').PackageJson} json
* @param {PackageJson} json
* @returns
*/
function getDepType(pkgName, json) {
Expand All @@ -95,7 +99,7 @@ function getDepType(pkgName, json) {
/**
*
* @param {string} project
* @param {import('@nx/devkit').ProjectGraph} projectGraph
* @param {ProjectGraph} projectGraph
* @param {*} options
* @param {Dependency[]} _acc
* @param {boolean} _areTopLevelDeps
Expand Down
Loading

0 comments on commit 415da9a

Please sign in to comment.