Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jsdoc type annotation to rules #1606

Merged
merged 6 commits into from Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions rules/better-regex.js
Expand Up @@ -14,6 +14,7 @@ const newRegExp = [
'[arguments.0.type="Literal"]',
].join('');

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const {sortCharacterClasses} = context.options[0] || {};

Expand Down Expand Up @@ -111,6 +112,7 @@ const schema = [
},
];

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/catch-error-name.js
Expand Up @@ -32,6 +32,7 @@ const selector = matches([
].join(''),
]);

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const options = {
name: 'error',
Expand Down Expand Up @@ -113,6 +114,7 @@ const schema = [
},
];

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/consistent-destructuring.js
Expand Up @@ -51,6 +51,7 @@ const isChildInParentScope = (child, parent) => {
return false;
};

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const source = context.getSourceCode();
const declarations = new Map();
Expand Down Expand Up @@ -149,6 +150,7 @@ const create = context => {
};
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/consistent-function-scoping.js
Expand Up @@ -149,6 +149,7 @@ function checkNode(node, scopeManager) {
return checkReferences(scope, parentScope, scopeManager);
}

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const {checkArrowFunctions} = {checkArrowFunctions: true, ...context.options[0]};
const sourceCode = context.getSourceCode();
Expand Down Expand Up @@ -206,6 +207,7 @@ const schema = [
},
];

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/custom-error-definition.js
Expand Up @@ -182,12 +182,14 @@ const customErrorExport = (context, node) => {
};
};

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => ({
ClassDeclaration: node => customErrorDefinition(context, node),
'AssignmentExpression[right.type="ClassExpression"]': node => customErrorDefinition(context, node.right),
'AssignmentExpression[left.type="MemberExpression"][left.object.type="Identifier"][left.object.name="exports"]': node => customErrorExport(context, node),
});

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
1 change: 1 addition & 0 deletions rules/empty-brace-spaces.js
Expand Up @@ -44,6 +44,7 @@ const create = context => ({
},
});

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/error-message.js
Expand Up @@ -25,6 +25,7 @@ const selector = callOrNewExpressionSelector([
'AggregateError',
]);

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => ({
[selector](expression) {
if (isShadowed(context.getScope(), expression.callee)) {
Expand Down Expand Up @@ -82,6 +83,7 @@ const create = context => ({
},
});

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/escape-case.js
Expand Up @@ -20,6 +20,7 @@ const getProblem = ({node, original, regex = escapeWithLowercase, fix}) => {
}
};

/** @param {import('eslint').Rule.RuleContext} context */
const create = () => ({
Literal(node) {
if (typeof node.value !== 'string') {
Expand Down Expand Up @@ -47,6 +48,7 @@ const create = () => ({
},
});

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/expiring-todo-comments.js
Expand Up @@ -242,6 +242,7 @@ function semverComparisonForOperator(operator) {
}[operator];
}

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const options = {
terms: ['todo', 'fixme', 'xxx'],
Expand Down Expand Up @@ -534,6 +535,7 @@ const schema = [
},
];

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
1 change: 1 addition & 0 deletions rules/explicit-length-check.js
Expand Up @@ -195,6 +195,7 @@ const schema = [
},
];

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create: checkVueTemplate(create),
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/filename-case.js
Expand Up @@ -142,6 +142,7 @@ function englishishJoinWords(words) {
return `${words.slice(0, -1).join(', ')}, or ${words[words.length - 1]}`;
}

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const options = context.options[0] || {};
const chosenCases = getChosenCases(options);
Expand Down Expand Up @@ -253,6 +254,7 @@ const schema = [
},
];

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/import-index.js
Expand Up @@ -20,6 +20,7 @@ const importIndex = (context, node, argument) => {
}
};

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const options = context.options[0] || {};

Expand Down Expand Up @@ -47,6 +48,7 @@ const schema = [
},
];

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/import-style.js
Expand Up @@ -150,6 +150,7 @@ const assignedRequireTemplate = templates.template`
${variableDeclarationVariable} ${assignmentTargetVariable} = require(${moduleNameVariable});
`;

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
let [
{
Expand Down Expand Up @@ -364,6 +365,7 @@ const schema = {
},
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/new-for-builtins.js
Expand Up @@ -12,6 +12,7 @@ const messages = {
disallow: 'Use `{{name}}()` instead of `new {{name}}()`.',
};

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const sourceCode = context.getSourceCode();

Expand Down Expand Up @@ -66,6 +67,7 @@ const create = context => {
};
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/no-abusive-eslint-disable.js
Expand Up @@ -7,6 +7,7 @@ const messages = {

const disableRegex = /^eslint-disable(?:-next-line|-line)?(?<ruleId>$|(?:\s+(?:@(?:[\w-]+\/){1,2})?[\w-]+)?)/;

/** @param {import('eslint').Rule.RuleContext} context */
const create = () => ({
* Program(node) {
for (const comment of node.comments) {
Expand Down Expand Up @@ -34,6 +35,7 @@ const create = () => ({
},
});

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/no-array-callback-reference.js
Expand Up @@ -187,6 +187,7 @@ const ignoredFirstArgumentSelector = [
'[arguments.0.type!="ArrowFunctionExpression"]',
].join('');

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const sourceCode = context.getSourceCode();
const rules = {};
Expand Down Expand Up @@ -220,6 +221,7 @@ const create = context => {
return rules;
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/no-array-for-each.js
Expand Up @@ -364,6 +364,7 @@ const ignoredObjects = [
'R',
];

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const functionStack = [];
const callExpressions = [];
Expand Down Expand Up @@ -416,6 +417,7 @@ const create = context => {
};
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
1 change: 1 addition & 0 deletions rules/no-array-method-this-argument.js
Expand Up @@ -159,6 +159,7 @@ const create = context => {
};
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
1 change: 1 addition & 0 deletions rules/no-array-push-push.js
Expand Up @@ -120,6 +120,7 @@ const schema = [
},
];

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/no-array-reduce.js
Expand Up @@ -48,6 +48,7 @@ const schema = [
},
];

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const {allowSimpleOperations} = {allowSimpleOperations: true, ...context.options[0]};

Expand Down Expand Up @@ -81,6 +82,7 @@ const create = context => {
};
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
1 change: 1 addition & 0 deletions rules/no-await-expression-member.js
Expand Up @@ -70,6 +70,7 @@ const create = context => {
};
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/no-console-spaces.js
Expand Up @@ -27,6 +27,7 @@ const hasLeadingSpace = value => value.length > 1 && value.charAt(0) === ' ' &&
// Find exactly one trailing space, allow exactly one space
const hasTrailingSpace = value => value.length > 1 && value.charAt(value.length - 1) === ' ' && value.charAt(value.length - 2) !== ' ';

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const sourceCode = context.getSourceCode();
const getProblem = (node, method, position) => {
Expand Down Expand Up @@ -71,6 +72,7 @@ const create = context => {
};
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
1 change: 1 addition & 0 deletions rules/no-document-cookie.js
Expand Up @@ -28,6 +28,7 @@ const create = context => ({
},
});

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/no-empty-file.js
Expand Up @@ -13,6 +13,7 @@ const isEmpty = node =>
|| node.type === 'EmptyStatement'
|| (node.type === 'ExpressionStatement' && 'directive' in node);

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const filename = context.getPhysicalFilename().toLowerCase();

Expand All @@ -34,6 +35,7 @@ const create = context => {
};
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/no-for-loop.js
Expand Up @@ -260,6 +260,7 @@ const someVariablesLeakOutOfTheLoop = (forStatement, variables, forScope) =>
const getReferencesInChildScopes = (scope, name) =>
getReferences(scope).filter(reference => reference.identifier.name === name);

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const sourceCode = context.getSourceCode();
const {scopeManager, text: sourceCodeText} = sourceCode;
Expand Down Expand Up @@ -411,6 +412,7 @@ const create = context => {
};
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/no-hex-escape.js
Expand Up @@ -21,6 +21,7 @@ function checkEscape(context, node, value) {
}
}

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => ({
Literal: node => {
if (node.regex || typeof node.value === 'string') {
Expand All @@ -30,6 +31,7 @@ const create = context => ({
TemplateElement: node => checkEscape(context, node, node.value.raw),
});

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
2 changes: 2 additions & 0 deletions rules/no-instanceof-array.js
Expand Up @@ -16,6 +16,7 @@ const selector = [
'[right.name="Array"]',
].join('');

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const sourceCode = context.getSourceCode();

Expand Down Expand Up @@ -48,6 +49,7 @@ const create = context => {
};
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create: checkVueTemplate(create),
meta: {
Expand Down
1 change: 1 addition & 0 deletions rules/no-invalid-remove-event-listener.js
Expand Up @@ -40,6 +40,7 @@ const create = context => ({
},
});

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down
1 change: 1 addition & 0 deletions rules/no-keyword-prefix.js
Expand Up @@ -189,6 +189,7 @@ const schema = [
},
];

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
Expand Down