eslint-plugin-flowtype
Advanced tools
Comparing version 8.0.1 to 8.0.2
@@ -31,5 +31,5 @@ #!/usr/bin/env node | ||
return null; | ||
} else { | ||
return match[1].replace('./rules/', '').replace('.md', ''); | ||
} | ||
return match[1].replace('./rules/', '').replace('.md', ''); | ||
}).filter(rule => { | ||
@@ -53,5 +53,5 @@ return rule !== null; | ||
return false; | ||
} else { | ||
return match[1] === name; | ||
} | ||
return match[1] === name; | ||
}; | ||
@@ -58,0 +58,0 @@ /** |
@@ -32,3 +32,5 @@ "use strict"; | ||
}); | ||
const rules = result.rules; | ||
const { | ||
rules | ||
} = result; | ||
@@ -35,0 +37,0 @@ if (rules.length === 0) { |
@@ -24,5 +24,5 @@ "use strict"; | ||
return inlined; | ||
} else { | ||
return 'Type'; | ||
} | ||
return 'Type'; | ||
}; | ||
@@ -77,5 +77,5 @@ | ||
return fixer.replaceText(node, '(' + rawElementType + ')[]'); | ||
} else { | ||
return fixer.replaceText(node, rawElementType + '[]'); | ||
} | ||
return fixer.replaceText(node, rawElementType + '[]'); | ||
}, | ||
@@ -82,0 +82,0 @@ |
@@ -18,5 +18,9 @@ "use strict"; | ||
if (!pattern.test(interfaceIdentifierName)) { | ||
context.report(interfaceDeclarationNode, 'Interface identifier \'{{name}}\' does not match pattern \'{{pattern}}\'.', { | ||
name: interfaceIdentifierName, | ||
pattern: pattern.toString() | ||
context.report({ | ||
data: { | ||
name: interfaceIdentifierName, | ||
pattern: pattern.toString() | ||
}, | ||
message: 'Interface identifier \'{{name}}\' does not match pattern \'{{pattern}}\'.', | ||
node: interfaceDeclarationNode | ||
}); | ||
@@ -23,0 +27,0 @@ } |
@@ -29,3 +29,3 @@ "use strict"; | ||
const potentialFlowFileAnnotation = _lodash.default.find(context.getAllComments(), comment => { | ||
const potentialFlowFileAnnotation = _lodash.default.find(context.getSourceCode().getAllComments(), comment => { | ||
return looksLikeFlowFileAnnotation(comment.value); | ||
@@ -35,3 +35,5 @@ }); | ||
if (potentialFlowFileAnnotation) { | ||
const line = potentialFlowFileAnnotation.loc.end.line; | ||
const { | ||
line | ||
} = potentialFlowFileAnnotation.loc.end; | ||
const nextLineIsEmpty = sourceCode.lines[line] === ''; | ||
@@ -38,0 +40,0 @@ |
@@ -32,3 +32,6 @@ "use strict"; | ||
if (/\$FlowFixMe/u.test(value) && !passesExtraRegex(value)) { | ||
context.report(comment, message + extraMessage); | ||
context.report({ | ||
message: message + extraMessage, | ||
node: comment | ||
}); | ||
} | ||
@@ -35,0 +38,0 @@ }; |
@@ -22,5 +22,5 @@ "use strict"; | ||
return _lodash.default.get(node, 'init.callee.name') === 'Array' && _lodash.default.get(node, 'init.arguments.length') === 0; | ||
} else { | ||
return false; | ||
} | ||
return false; | ||
}; | ||
@@ -34,5 +34,5 @@ | ||
return isVariableDeclaration && (isEmptyArrayLiteral(parent) || isEmptyArrayInstance(parent)); | ||
} else { | ||
return false; | ||
} | ||
return false; | ||
}; | ||
@@ -39,0 +39,0 @@ |
@@ -13,3 +13,5 @@ "use strict"; | ||
const noUnusedExpressionsRule = (0, _getBuiltinRule.getBuiltinRule)('no-unused-expressions'); | ||
const meta = noUnusedExpressionsRule.meta; | ||
const { | ||
meta | ||
} = noUnusedExpressionsRule; | ||
@@ -16,0 +18,0 @@ const create = context => { |
@@ -53,5 +53,5 @@ "use strict"; | ||
}; | ||
} else { | ||
return {}; | ||
} | ||
return {}; | ||
}; | ||
@@ -58,0 +58,0 @@ |
@@ -37,5 +37,5 @@ "use strict"; | ||
}; | ||
} else { | ||
return {}; | ||
} | ||
return {}; | ||
}; | ||
@@ -42,0 +42,0 @@ |
@@ -50,3 +50,5 @@ "use strict"; | ||
return true; | ||
} else if (node.exact === true) { | ||
} | ||
if (node.exact === true) { | ||
return true; | ||
@@ -53,0 +55,0 @@ } |
@@ -126,7 +126,16 @@ "use strict"; | ||
if (isFunctionReturnUndefined && isReturnTypeAnnotationUndefined && annotateUndefined === 'never') { | ||
context.report(functionNode, 'Must not annotate undefined return type.'); | ||
context.report({ | ||
message: 'Must not annotate undefined return type.', | ||
node: functionNode | ||
}); | ||
} else if (isFunctionReturnUndefined && !isReturnTypeAnnotationUndefined && annotateUndefined === 'always') { | ||
context.report(functionNode, 'Must annotate undefined return type.'); | ||
context.report({ | ||
message: 'Must annotate undefined return type.', | ||
node: functionNode | ||
}); | ||
} else if ((annotateUndefined === 'always-enforce' || !isFunctionReturnUndefined && !isReturnTypeAnnotationUndefined) && annotateReturn && !returnType && !shouldFilterNode(functionNode)) { | ||
context.report(functionNode, 'Missing return type annotation.'); | ||
context.report({ | ||
message: 'Missing return type annotation.', | ||
node: functionNode | ||
}); | ||
} | ||
@@ -133,0 +142,0 @@ }; |
@@ -75,5 +75,5 @@ "use strict"; | ||
}; | ||
} else { | ||
return {}; | ||
} | ||
return {}; | ||
}; | ||
@@ -80,0 +80,0 @@ |
@@ -72,3 +72,3 @@ "use strict"; | ||
const potentialFlowFileAnnotation = _lodash.default.find(context.getAllComments(), comment => { | ||
const potentialFlowFileAnnotation = _lodash.default.find(context.getSourceCode().getAllComments(), comment => { | ||
return looksLikeFlowFileAnnotation(comment.value); | ||
@@ -79,3 +79,6 @@ }); | ||
if (firstToken && firstToken.range[0] < potentialFlowFileAnnotation.range[0]) { | ||
context.report(potentialFlowFileAnnotation, 'Flow file annotation not at the top of the file.'); | ||
context.report({ | ||
message: 'Flow file annotation not at the top of the file.', | ||
node: potentialFlowFileAnnotation | ||
}); | ||
} | ||
@@ -109,5 +112,11 @@ | ||
} else if (checkAnnotationSpelling(annotationValue)) { | ||
context.report(potentialFlowFileAnnotation, 'Misspelled or malformed Flow file annotation.'); | ||
context.report({ | ||
message: 'Misspelled or malformed Flow file annotation.', | ||
node: potentialFlowFileAnnotation | ||
}); | ||
} else { | ||
context.report(potentialFlowFileAnnotation, 'Malformed Flow file annotation.'); | ||
context.report({ | ||
message: 'Malformed Flow file annotation.', | ||
node: potentialFlowFileAnnotation | ||
}); | ||
} | ||
@@ -114,0 +123,0 @@ } else if (always && !_lodash.default.get(context, 'settings.flowtype.onlyFilesWithFlowAnnotation')) { |
@@ -28,2 +28,3 @@ "use strict"; | ||
const getGroup = node => { | ||
// eslint-disable-next-line default-case | ||
switch (node.type) { | ||
@@ -30,0 +31,0 @@ case 'FunctionTypeAnnotation': |
@@ -20,5 +20,5 @@ "use strict"; | ||
return sourceCode.getFirstToken(node, node.optional ? 2 : 1); | ||
} else { | ||
return sourceCode.getFirstToken(typeAnnotation); | ||
} | ||
return sourceCode.getFirstToken(typeAnnotation); | ||
}; | ||
@@ -25,0 +25,0 @@ |
@@ -15,5 +15,5 @@ "use strict"; | ||
return colon.loc.start.line !== sourceCode.getTokenBefore(colon).loc.end.line; | ||
} else { | ||
return sourceCode.getTokenAfter(colon).loc.start.line !== colon.loc.end.line; | ||
} | ||
return sourceCode.getTokenAfter(colon).loc.start.line !== colon.loc.end.line; | ||
}; | ||
@@ -26,5 +26,5 @@ | ||
return colon.range[0] - sourceCode.getTokenBefore(colon).range[1]; | ||
} else { | ||
return sourceCode.getTokenAfter(colon).range[0] - colon.range[1]; | ||
} | ||
return sourceCode.getTokenAfter(colon).range[0] - colon.range[1]; | ||
}; | ||
@@ -31,0 +31,0 @@ |
@@ -18,5 +18,9 @@ "use strict"; | ||
if (!pattern.test(typeIdentifierName)) { | ||
context.report(typeAliasNode, 'Type identifier \'{{name}}\' does not match pattern \'{{pattern}}\'.', { | ||
name: typeIdentifierName, | ||
pattern: pattern.toString() | ||
context.report({ | ||
data: { | ||
name: typeIdentifierName, | ||
pattern: pattern.toString() | ||
}, | ||
message: 'Type identifier \'{{name}}\' does not match pattern \'{{pattern}}\'.', | ||
node: typeAliasNode | ||
}); | ||
@@ -23,0 +27,0 @@ } |
@@ -37,52 +37,54 @@ "use strict"; | ||
}; | ||
} else { | ||
// Default to 'identifier' | ||
const ignoreTypeDefault = context.options[1] && context.options[1].ignoreTypeDefault; | ||
let isInsideDeclareModule = false; | ||
return { | ||
DeclareModule() { | ||
isInsideDeclareModule = true; | ||
}, | ||
} // Default to 'identifier' | ||
'DeclareModule:exit'() { | ||
isInsideDeclareModule = false; | ||
}, | ||
ImportDeclaration(node) { | ||
if (node.importKind !== 'type') { | ||
return; | ||
} // type specifiers are not allowed inside module declarations: | ||
// https://github.com/facebook/flow/issues/7609 | ||
const ignoreTypeDefault = context.options[1] && context.options[1].ignoreTypeDefault; | ||
let isInsideDeclareModule = false; | ||
return { | ||
DeclareModule() { | ||
isInsideDeclareModule = true; | ||
}, | ||
'DeclareModule:exit'() { | ||
isInsideDeclareModule = false; | ||
}, | ||
if (isInsideDeclareModule) { | ||
return; | ||
} | ||
ImportDeclaration(node) { | ||
if (node.importKind !== 'type') { | ||
return; | ||
} // type specifiers are not allowed inside module declarations: | ||
// https://github.com/facebook/flow/issues/7609 | ||
if (ignoreTypeDefault && node.specifiers[0] && node.specifiers[0].type === 'ImportDefaultSpecifier') { | ||
return; | ||
} | ||
context.report({ | ||
fix(fixer) { | ||
const imports = node.specifiers.map(specifier => { | ||
if (specifier.type === 'ImportDefaultSpecifier') { | ||
return 'type default as ' + specifier.local.name; | ||
} else if (specifier.imported.name === specifier.local.name) { | ||
return 'type ' + specifier.local.name; | ||
} else { | ||
return 'type ' + specifier.imported.name + ' as ' + specifier.local.name; | ||
} | ||
}); | ||
const source = node.source.value; | ||
return fixer.replaceText(node, 'import {' + imports.join(', ') + '} from \'' + source + '\';'); | ||
}, | ||
if (isInsideDeclareModule) { | ||
return; | ||
} | ||
message: 'Unexpected "import type"', | ||
node | ||
}); | ||
if (ignoreTypeDefault && node.specifiers[0] && node.specifiers[0].type === 'ImportDefaultSpecifier') { | ||
return; | ||
} | ||
}; | ||
} | ||
context.report({ | ||
fix(fixer) { | ||
const imports = node.specifiers.map(specifier => { | ||
if (specifier.type === 'ImportDefaultSpecifier') { | ||
return 'type default as ' + specifier.local.name; | ||
} | ||
if (specifier.imported.name === specifier.local.name) { | ||
return 'type ' + specifier.local.name; | ||
} | ||
return 'type ' + specifier.imported.name + ' as ' + specifier.local.name; | ||
}); | ||
const source = node.source.value; | ||
return fixer.replaceText(node, 'import {' + imports.join(', ') + '} from \'' + source + '\';'); | ||
}, | ||
message: 'Unexpected "import type"', | ||
node | ||
}); | ||
} | ||
}; | ||
}; | ||
@@ -89,0 +91,0 @@ |
@@ -66,5 +66,5 @@ "use strict"; | ||
return id.value; | ||
} else { | ||
return null; | ||
} | ||
return null; | ||
} | ||
@@ -81,5 +81,5 @@ | ||
return text.replace(context.getSourceCode().getText(identifierNode.typeAnnotation), '').trim(); | ||
} else { | ||
return text; | ||
} | ||
return text; | ||
} | ||
@@ -86,0 +86,0 @@ |
@@ -59,5 +59,5 @@ "use strict"; | ||
return stripSpacesBefore(node, spaces); | ||
} else { | ||
return stripSpacesAfter(node, spaces); | ||
} | ||
return stripSpacesAfter(node, spaces); | ||
}; | ||
@@ -70,5 +70,5 @@ | ||
return addSpaceBefore(node); | ||
} else { | ||
return addSpaceAfter(node); | ||
} | ||
return addSpaceAfter(node); | ||
}; | ||
@@ -81,7 +81,7 @@ | ||
return replaceWithSpaceBefore(node, spaces); | ||
} else { | ||
return replaceWithSpaceAfter(node, spaces); | ||
} | ||
return replaceWithSpaceAfter(node, spaces); | ||
}; | ||
exports.replaceWithSpace = replaceWithSpace; |
@@ -25,4 +25,4 @@ { | ||
"eslint": "^8.1.0", | ||
"eslint-config-canonical": "^32.6.0", | ||
"eslint-plugin-eslint-plugin": "^4.0.1", | ||
"eslint-config-canonical": "^32.10.0", | ||
"eslint-plugin-eslint-plugin": "^4.0.2", | ||
"gitdown": "^3.1.4", | ||
@@ -69,3 +69,3 @@ "glob": "^7.2.0", | ||
}, | ||
"version": "8.0.1" | ||
"version": "8.0.2" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
335226
4379