Skip to content

Commit 084c678

Browse files
committed
[Build]: fix type-check errors
1 parent d344dca commit 084c678

25 files changed

+72
-45
lines changed

lib/rules/destructuring-assignment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ module.exports = {
127127
handleSFCUsage(node);
128128
}
129129
if (classComponent) {
130-
handleClassUsage(node, classComponent);
130+
handleClassUsage(node);
131131
}
132132
},
133133

lib/rules/jsx-closing-bracket-location.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ module.exports = {
198198
}
199199
const openingLine = sourceCode.lines[opening.line - 1];
200200
const openingStartOfLine = {
201+
// @ts-ignore
201202
column: /^\s*/.exec(openingLine)[0].length,
202203
line: opening.line
203204
};
@@ -274,7 +275,7 @@ module.exports = {
274275
case 'tag-aligned':
275276
case 'line-aligned':
276277
return fixer.replaceTextRange([cachedLastAttributeEndPos, node.range[1]],
277-
`\n${getIndentation(tokens, expectedLocation, correctColumn)}${closingTag}`);
278+
`\n${getIndentation(tokens, expectedLocation, correctColumn || 0)}${closingTag}`);
278279
default:
279280
return true;
280281
}

lib/rules/jsx-curly-brace-presence.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ module.exports = {
110110

111111
/**
112112
* Report and fix an unnecessary curly brace violation on a node
113-
* @param {ASTNode} node - The AST node with an unnecessary JSX expression
113+
* @param {ASTNode} JSXExpressionNode - The AST node with an unnecessary JSX expression
114114
*/
115115
function reportUnnecessaryCurly(JSXExpressionNode) {
116116
context.report({

lib/rules/jsx-curly-spacing.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ module.exports = {
156156
/**
157157
* Trims text of whitespace between two ranges
158158
* @param {Fixer} fixer - the eslint fixer object
159-
* @param {Location} fromLoc - the start location
160-
* @param {Location} toLoc - the end location
159+
* @param {number} fromLoc - the start location
160+
* @param {number} toLoc - the end location
161161
* @param {string} mode - either 'start' or 'end'
162162
* @param {string=} spacing - a spacing value that will optionally add a space to the removed text
163163
* @returns {Object|*|{range, text}}
@@ -183,6 +183,7 @@ module.exports = {
183183
* Reports that there shouldn't be a newline after the first token
184184
* @param {ASTNode} node - The node to report in the event of an error.
185185
* @param {Token} token - The token to use for the report.
186+
* @param {string} spacing
186187
* @returns {void}
187188
*/
188189
function reportNoBeginningNewline(node, token, spacing) {
@@ -201,6 +202,7 @@ module.exports = {
201202
* Reports that there shouldn't be a newline before the last token
202203
* @param {ASTNode} node - The node to report in the event of an error.
203204
* @param {Token} token - The token to use for the report.
205+
* @param {string} spacing
204206
* @returns {void}
205207
*/
206208
function reportNoEndingNewline(node, token, spacing) {

lib/rules/jsx-indent-props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module.exports = {
5959

6060
const extraColumnStart = 0;
6161
let indentType = 'space';
62+
/** @type {number|'first'} */
6263
let indentSize = 4;
6364

6465
const sourceCode = context.getSourceCode();
@@ -126,7 +127,6 @@ module.exports = {
126127
* Check indent for nodes list
127128
* @param {ASTNode[]} nodes list of node objects
128129
* @param {Number} indent needed indent
129-
* @param {Boolean} excludeCommas skip comma on start of line
130130
*/
131131
function checkNodesIndent(nodes, indent) {
132132
nodes.forEach(node => {

lib/rules/jsx-indent.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ module.exports = {
110110
* @param {ASTNode} node Node violating the indent rule
111111
* @param {Number} needed Expected indentation character count
112112
* @param {Number} gotten Indentation character count in the actual node/code
113-
* @param {Object} loc Error line and column location
113+
* @param {Object} [loc] Error line and column location
114114
*/
115115
function report(node, needed, gotten, loc) {
116116
const msgContext = {
@@ -141,8 +141,8 @@ module.exports = {
141141
/**
142142
* Get node indent
143143
* @param {ASTNode} node Node to examine
144-
* @param {Boolean} byLastLine get indent of node's last line
145-
* @param {Boolean} excludeCommas skip comma on start of line
144+
* @param {Boolean} [byLastLine] get indent of node's last line
145+
* @param {Boolean} [excludeCommas] skip comma on start of line
146146
* @return {Number} Indent
147147
*/
148148
function getNodeIndent(node, byLastLine, excludeCommas) {
@@ -204,7 +204,7 @@ module.exports = {
204204
* Check indent for nodes list
205205
* @param {ASTNode} node The node to check
206206
* @param {Number} indent needed indent
207-
* @param {Boolean} excludeCommas skip comma on start of line
207+
* @param {Boolean} [excludeCommas] skip comma on start of line
208208
*/
209209
function checkNodesIndent(node, indent, excludeCommas) {
210210
const nodeIndent = getNodeIndent(node, false, excludeCommas);

lib/rules/jsx-sort-props.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function contextCompare(a, b, options) {
7575
* Create an array of arrays where each subarray is composed of attributes
7676
* that are considered sortable.
7777
* @param {Array<JSXSpreadAttribute|JSXAttribute>} attributes
78-
* @return {Array<Array<JSXAttribute>}
78+
* @return {Array<Array<JSXAttribute>>}
7979
*/
8080
function getGroupsOfSortableAttributes(attributes) {
8181
const sortableAttributeGroups = [];
@@ -156,7 +156,7 @@ const generateFixerFunction = (node, context, reservedList) => {
156156
* Checks if the `reservedFirst` option is valid
157157
* @param {Object} context The context of the rule
158158
* @param {Boolean|Array<String>} reservedFirst The `reservedFirst` option
159-
* @return {?Function} If an error is detected, a function to generate the error message, otherwise, `undefined`
159+
* @return {Function|undefined} If an error is detected, a function to generate the error message, otherwise, `undefined`
160160
*/
161161
// eslint-disable-next-line consistent-return
162162
function validateReservedFirstConfig(context, reservedFirst) {

lib/rules/no-danger-with-children.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = {
2828
* Takes a ObjectExpression and returns the value of the prop if it has it
2929
* @param {object} node - ObjectExpression node
3030
* @param {string} propName - name of the prop to look for
31+
* @param {any[]} seenProps
3132
*/
3233
function findObjectProp(node, propName, seenProps) {
3334
if (!node.properties) {

lib/rules/no-unknown-property.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ function isTagName(node) {
157157

158158
/**
159159
* Extracts the tag name for the JSXAttribute
160-
* @param {Object} node - JSXAttribute being tested.
161-
* @returns {String} tag name
160+
* @param {JSXAttribute} node - JSXAttribute being tested.
161+
* @returns {String|null} tag name
162162
*/
163163
function getTagName(node) {
164164
if (node && node.parent && node.parent.name && node.parent.name) {
@@ -184,7 +184,7 @@ function tagNameHasDot(node) {
184184
/**
185185
* Get the standard name of the attribute.
186186
* @param {String} name - Name of the attribute.
187-
* @returns {String} The standard name of the attribute.
187+
* @returns {String|undefined} The standard name of the attribute.
188188
*/
189189
function getStandardName(name) {
190190
if (DOM_ATTRIBUTE_NAMES[name]) {
@@ -193,12 +193,9 @@ function getStandardName(name) {
193193
if (SVGDOM_ATTRIBUTE_NAMES[name]) {
194194
return SVGDOM_ATTRIBUTE_NAMES[name];
195195
}
196-
let i;
197-
const found = DOM_PROPERTY_NAMES.some((element, index) => {
198-
i = index;
199-
return element.toLowerCase() === name;
200-
});
201-
return found ? DOM_PROPERTY_NAMES[i] : null;
196+
197+
const found = DOM_PROPERTY_NAMES.find(domPropertyName => domPropertyName.toLowerCase() === name);
198+
return found || null;
202199
}
203200

204201
// ------------------------------------------------------------------------------

lib/rules/no-unused-prop-types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ module.exports = {
8282
/**
8383
* Used to recursively loop through each declared prop type
8484
* @param {Object} component The component to process
85-
* @param {Array} props List of props to validate
85+
* @param {ASTNode[]|true} props List of props to validate
8686
*/
8787
function reportUnusedPropType (component, props) {
8888
// Skip props that check instances

lib/rules/no-unused-state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ module.exports = {
101101
parent &&
102102
parent.type === 'MethodDefinition' && (
103103
parent.static && parent.key.name === 'getDerivedStateFromProps' ||
104-
classMethods.indexOf(parent.key.name !== -1)
104+
classMethods.indexOf(parent.key.name) !== -1
105105
) &&
106106
parent.value.type === 'FunctionExpression' &&
107107
parent.value.params[1] &&

lib/rules/prefer-stateless-function.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ module.exports = {
137137
* Checks whether the parameters of a constructor and the arguments of `super()`
138138
* have the same values or not.
139139
* @see ESLint no-useless-constructor rule
140-
* @param {ASTNode} ctorParams - The parameters of a constructor to check.
140+
* @param {ASTNode[]} ctorParams - The parameters of a constructor to check.
141141
* @param {ASTNode} superArgs - The arguments of `super()` to check.
142142
* @returns {boolean} `true` if those have the same values.
143143
*/

lib/rules/static-property-placement.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ module.exports = {
102102

103103
/**
104104
* Check if we should report this property node
105-
* @param node
106-
* @param expectedRule
105+
* @param {ASTNode} node
106+
* @param {string} expectedRule
107107
*/
108108
function reportNodeIncorrectlyPositioned(node, expectedRule) {
109109
// Detect if this node is an expected property declaration adn return the property name
110110
const name = classProperties.find(propertyName => {
111111
if (propertiesToCheck[propertyName](node)) {
112-
return propertyName;
112+
return !!propertyName;
113113
}
114114

115-
return null;
115+
return false;
116116
});
117117

118118
// If name is set but the configured rule does not match expected then report error

lib/rules/style-prop-object.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = {
2424

2525
create: function(context) {
2626
/**
27-
* @param {object} node An Identifier node
27+
* @param {ASTNode} expression An Identifier node
2828
*/
2929
function isNonNullaryLiteral(expression) {
3030
return expression.type === 'Literal' && expression.value !== null;

lib/types.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as eslint from 'eslint';
2+
import * as estree from 'estree';
3+
4+
declare global {
5+
interface ASTNode extends estree.BaseNode {
6+
[_: string]: any;
7+
}
8+
type Scope = eslint.Scope.Scope;
9+
type Token = eslint.AST.Token;
10+
type Fixer = eslint.Rule.RuleFixer;
11+
type JSXAttribute = ASTNode;
12+
type JSXSpreadAttribute = ASTNode;
13+
}

lib/util/Components.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ function componentRule(rule, context) {
258258
/**
259259
* Check if variable is destructured from pragma import
260260
*
261-
* @param {variable} String The variable name to check
261+
* @param {string} variable The variable name to check
262262
* @returns {Boolean} True if createElement is destructured from the pragma
263263
*/
264264
isDestructuredFromPragmaImport: function(variable) {
@@ -351,7 +351,7 @@ function componentRule(rule, context) {
351351
* Check if the node is returning JSX
352352
*
353353
* @param {ASTNode} ASTnode The AST node being checked
354-
* @param {Boolean} strict If true, in a ternary condition the node must return JSX in both cases
354+
* @param {Boolean} [strict] If true, in a ternary condition the node must return JSX in both cases
355355
* @returns {Boolean} True if the node is returning JSX, false if not
356356
*/
357357
isReturningJSX: function(ASTnode, strict) {
@@ -413,7 +413,7 @@ function componentRule(rule, context) {
413413
* Check if the node is returning JSX or null
414414
*
415415
* @param {ASTNode} ASTnode The AST node being checked
416-
* @param {Boolean} strict If true, in a ternary condition the node must return JSX in both cases
416+
* @param {Boolean} [strict] If true, in a ternary condition the node must return JSX in both cases
417417
* @returns {Boolean} True if the node is returning JSX or null, false if not
418418
*/
419419
isReturningJSXOrNull(ASTNode, strict) {

lib/util/annotations.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/**
99
* Checks if we are declaring a `props` argument with a flow type annotation.
1010
* @param {ASTNode} node The AST node being checked.
11+
* @param {Object} context
1112
* @returns {Boolean} True if the node is a type annotated props declaration, false if not.
1213
*/
1314
function isAnnotatedFunctionPropsDeclaration(node, context) {

lib/util/ast.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* Find a return statment in the current node
88
*
9-
* @param {ASTNode} ASTnode The AST node being checked
9+
* @param {ASTNode} node The AST node being checked
1010
*/
1111
function findReturnStatement(node) {
1212
if (
@@ -114,7 +114,7 @@ function isNodeFirstInLine(context, node) {
114114

115115
/**
116116
* Checks if the node is a function or arrow function expression.
117-
* @param {Object} context The node to check
117+
* @param {ASTNode} node The node to check
118118
* @return {Boolean} true if it's a function-like expression
119119
*/
120120
function isFunctionLikeExpression(node) {
@@ -123,7 +123,7 @@ function isFunctionLikeExpression(node) {
123123

124124
/**
125125
* Checks if the node is a function.
126-
* @param {Object} context The node to check
126+
* @param {ASTNode} node The node to check
127127
* @return {Boolean} true if it's a function
128128
*/
129129
function isFunction(node) {
@@ -132,7 +132,7 @@ function isFunction(node) {
132132

133133
/**
134134
* Checks if the node is an arrow function.
135-
* @param {Object} context The node to check
135+
* @param {ASTNode} node The node to check
136136
* @return {Boolean} true if it's an arrow function
137137
*/
138138
function isArrowFunction(node) {
@@ -141,7 +141,7 @@ function isArrowFunction(node) {
141141

142142
/**
143143
* Checks if the node is a class.
144-
* @param {Object} context The node to check
144+
* @param {ASTNode} node The node to check
145145
* @return {Boolean} true if it's a class
146146
*/
147147
function isClass(node) {

lib/util/defaultProps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module.exports = function defaultPropsInstructions(context, components, utils) {
7070
/**
7171
* Adds defaultProps to the component passed in.
7272
* @param {ASTNode} component The component to add the defaultProps to.
73-
* @param {String[]|String} defaultProps defaultProps to add to the component or the string "unresolved"
73+
* @param {Object[]|'unresolved'} defaultProps defaultProps to add to the component or the string "unresolved"
7474
* if this component has defaultProps that can't be resolved.
7575
* @returns {void}
7676
*/

lib/util/linkComponents.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
'use strict';
55

6+
/** @type {any[]}} */
67
const DEFAULT_LINK_COMPONENTS = ['a'];
78
const DEFAULT_LINK_ATTRIBUTE = 'href';
89

0 commit comments

Comments
 (0)