Skip to content

Commit a659b63

Browse files
authored
Merge pull request #2267 from golopot/fix-some-jsdoc-errors
[tests] check jsdoc using typescript with `--checkJs`
2 parents eb90ce6 + 3e7c1f6 commit a659b63

26 files changed

+121
-45
lines changed

.eslintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,6 @@
168168
"no-plusplus": 0,
169169
"no-prototype-builtins": 2,
170170
"prefer-template": 2,
171-
"template-curly-spacing": [2, "never"],
171+
"template-curly-spacing": [2, "never"]
172172
}
173173
}

lib/rules/destructuring-assignment.js

+1-1
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,11 @@ module.exports = {
153153
* Get the characters used for indentation on the line to be matched
154154
* @param {Object} tokens Locations of the opening bracket, closing bracket and last prop
155155
* @param {String} expectedLocation Expected location for the closing bracket
156-
* @param {Number} correctColumn Expected column for the closing bracket
156+
* @param {Number} [correctColumn] Expected column for the closing bracket. Default to 0
157157
* @return {String} The characters used for indentation
158158
*/
159159
function getIndentation(tokens, expectedLocation, correctColumn) {
160+
correctColumn = correctColumn || 0;
160161
let indentation, spaces = [];
161162
switch (expectedLocation) {
162163
case 'props-aligned':

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

+1-1
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

+4-2
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

+1-1
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

+4-4
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

+2-2
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

+1
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 {string[]} seenProps
3132
*/
3233
function findObjectProp(node, propName, seenProps) {
3334
if (!node.properties) {

lib/rules/no-unknown-property.js

+3-3
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) {
@@ -193,7 +193,7 @@ function getStandardName(name) {
193193
if (SVGDOM_ATTRIBUTE_NAMES[name]) {
194194
return SVGDOM_ATTRIBUTE_NAMES[name];
195195
}
196-
let i;
196+
let i = -1;
197197
const found = DOM_PROPERTY_NAMES.some((element, index) => {
198198
i = index;
199199
return element.toLowerCase() === name;

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

+1-1
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/prefer-stateless-function.js

+1-1
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

+4-4
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

+1-1
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

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import eslint from 'eslint';
2+
import estree from 'estree';
3+
4+
declare global {
5+
interface ASTNode extends estree.BaseNode {
6+
[_: string]: any; // TODO: fixme
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+
14+
interface Context extends eslint.SourceCode {
15+
getFirstTokens(node: estree.Node | ASTNode, options?: eslint.SourceCode.CursorWithCountOptions): eslint.AST.Token[];
16+
}
17+
18+
type TypeDeclarationBuilder = (annotation: ASTNode, parentName: string, seen: Set<typeof annotation>) => object;
19+
20+
type TypeDeclarationBuilders = {
21+
[k in string]: TypeDeclarationBuilder;
22+
};
23+
24+
type UnionTypeDefinitionChildren = unknown[];
25+
type UnionTypeDefinition = {
26+
type: 'union' | 'shape';
27+
children: UnionTypeDefinitionChildren | true;
28+
};
29+
}

lib/util/Components.js

+3-3
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

+1
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

+5-5
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

+1-1
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

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
*/
44
'use strict';
55

6+
/** TODO: type {(string | { name: string, linkAttribute: string })[]} */
7+
/** @type {any} */
68
const DEFAULT_LINK_COMPONENTS = ['a'];
79
const DEFAULT_LINK_ATTRIBUTE = 'href';
810

911
function getLinkComponents(context) {
1012
const settings = context.settings || {};
11-
return new Map(DEFAULT_LINK_COMPONENTS.concat(settings.linkComponents || []).map(value => {
13+
const linkComponents = /** @type {typeof DEFAULT_LINK_COMPONENTS} */ (
14+
DEFAULT_LINK_COMPONENTS.concat(settings.linkComponents || [])
15+
);
16+
return new Map(linkComponents.map(value => {
1217
if (typeof value === 'string') {
1318
return [value, DEFAULT_LINK_ATTRIBUTE];
1419
}

0 commit comments

Comments
 (0)