eslint-plugin-etc
Advanced tools
Comparing version 1.3.5 to 1.3.6
@@ -0,1 +1,10 @@ | ||
<a name="1.3.6"></a> | ||
## [1.3.6](https://github.com/cartant/eslint-plugin-etc/compare/v1.3.5...v1.3.6) (2021-03-20) | ||
## Fixes | ||
- Support multiple `@deprecated` and `@internal` tags in the `no-deprecated` and `no-internal` rules. ([20eb236](https://github.com/cartant/eslint-plugin-etc/commit/20eb236)) | ||
- Enable TypeScript's `strict` option and fix related problems. ([826953c](https://github.com/cartant/eslint-plugin-etc/commit/826953c)) | ||
<a name="1.3.5"></a> | ||
@@ -2,0 +11,0 @@ |
@@ -0,2 +1,3 @@ | ||
"use strict"; | ||
module.exports.configs = require("requireindex")(`${__dirname}/configs`); | ||
module.exports.rules = require("requireindex")(`${__dirname}/rules`); |
"use strict"; | ||
const eslint_etc_1 = require("eslint-etc"); | ||
const utils_1 = require("../utils"); | ||
function isNewExpression(node) { | ||
return node.type === "NewExpression"; | ||
} | ||
const mutatorRegExp = /^(fill|reverse|sort)$/; | ||
@@ -31,3 +28,3 @@ const creatorRegExp = /^(concat|entries|filter|keys|map|slice|splice|values)$/; | ||
const parent = eslint_etc_1.getParent(callExpression); | ||
if (!eslint_etc_1.isExpressionStatement(parent)) { | ||
if (parent && !eslint_etc_1.isExpressionStatement(parent)) { | ||
if (couldBeType(memberExpression.object, "Array") && | ||
@@ -47,3 +44,3 @@ mutatesReferencedArray(callExpression)) { | ||
} | ||
if (isNewExpression(node)) { | ||
if (eslint_etc_1.isNewExpression(node)) { | ||
return true; | ||
@@ -50,0 +47,0 @@ } |
@@ -53,7 +53,4 @@ "use strict"; | ||
}; | ||
let deprecatedNames; | ||
if (deprecatedNamesByProgram.has(program)) { | ||
deprecatedNames = deprecatedNamesByProgram.get(program); | ||
} | ||
else { | ||
let deprecatedNames = deprecatedNamesByProgram.get(program); | ||
if (!deprecatedNames) { | ||
deprecatedNames = tag_1.findTaggedNames("deprecated", program); | ||
@@ -64,3 +61,4 @@ deprecatedNamesByProgram.set(program, deprecatedNames); | ||
Identifier: (node) => { | ||
switch (eslint_etc_1.getParent(node).type) { | ||
var _a; | ||
switch ((_a = eslint_etc_1.getParent(node)) === null || _a === void 0 ? void 0 : _a.type) { | ||
case "ExportSpecifier": | ||
@@ -75,3 +73,3 @@ case "ImportDefaultSpecifier": | ||
const identifier = esTreeNodeToTSNodeMap.get(node); | ||
if (!deprecatedNames.has(identifier.text)) { | ||
if (!(deprecatedNames === null || deprecatedNames === void 0 ? void 0 : deprecatedNames.has(identifier.text))) { | ||
return; | ||
@@ -86,12 +84,14 @@ } | ||
} | ||
const tag = tslint_tag_1.getTag("deprecated", identifier, typeChecker); | ||
if (tag !== undefined) { | ||
context.report({ | ||
data: { | ||
comment: tag.trim().replace(/[\n\r\s\t]+/g, " "), | ||
name: identifier.text, | ||
}, | ||
messageId: "forbidden", | ||
node, | ||
}); | ||
const tags = tslint_tag_1.getTags("deprecated", identifier, typeChecker); | ||
if (tags.length > 0) { | ||
for (const tag of tags) { | ||
context.report({ | ||
data: { | ||
comment: tag.trim().replace(/[\n\r\s\t]+/g, " "), | ||
name: identifier.text, | ||
}, | ||
messageId: "forbidden", | ||
node, | ||
}); | ||
} | ||
} | ||
@@ -98,0 +98,0 @@ }, |
@@ -8,3 +8,4 @@ "use strict"; | ||
const after = sourceCode.getTokenAfter(node); | ||
return (Boolean(before && after) && | ||
return (before && | ||
after && | ||
before.value === "(" && | ||
@@ -11,0 +12,0 @@ before.range[1] <= node.range[0] && |
@@ -53,7 +53,4 @@ "use strict"; | ||
}; | ||
let internalNames; | ||
if (internalNamesByProgram.has(program)) { | ||
internalNames = internalNamesByProgram.get(program); | ||
} | ||
else { | ||
let internalNames = internalNamesByProgram.get(program); | ||
if (!internalNames) { | ||
internalNames = tag_1.findTaggedNames("internal", program); | ||
@@ -64,3 +61,4 @@ internalNamesByProgram.set(program, internalNames); | ||
Identifier: (node) => { | ||
switch (eslint_etc_1.getParent(node).type) { | ||
var _a; | ||
switch ((_a = eslint_etc_1.getParent(node)) === null || _a === void 0 ? void 0 : _a.type) { | ||
case "ExportSpecifier": | ||
@@ -75,3 +73,3 @@ case "ImportDefaultSpecifier": | ||
const identifier = esTreeNodeToTSNodeMap.get(node); | ||
if (!internalNames.has(identifier.text)) { | ||
if (!(internalNames === null || internalNames === void 0 ? void 0 : internalNames.has(identifier.text))) { | ||
return; | ||
@@ -86,9 +84,14 @@ } | ||
} | ||
const comment = tslint_tag_1.getTag("internal", identifier, typeChecker); | ||
if (comment !== undefined) { | ||
context.report({ | ||
data: { comment, name: identifier.text }, | ||
messageId: "forbidden", | ||
node, | ||
}); | ||
const tags = tslint_tag_1.getTags("internal", identifier, typeChecker); | ||
if (tags.length > 0) { | ||
for (const tag of tags) { | ||
context.report({ | ||
data: { | ||
comment: tag.trim().replace(/[\n\r\s\t]+/g, " "), | ||
name: identifier.text, | ||
}, | ||
messageId: "forbidden", | ||
node, | ||
}); | ||
} | ||
} | ||
@@ -95,0 +98,0 @@ }, |
"use strict"; | ||
const eslint_etc_1 = require("eslint-etc"); | ||
const utils_1 = require("../utils"); | ||
function isExportNamedDeclaration(node) { | ||
return node.type === "ExportNamedDeclaration"; | ||
} | ||
function isTSTypeLiteral(node) { | ||
return node.type === "TSTypeLiteral"; | ||
} | ||
function isTSTypeReference(node) { | ||
return node.type === "TSTypeReference"; | ||
} | ||
const defaultOptions = []; | ||
@@ -59,3 +50,4 @@ const rule = utils_1.ruleCreator({ | ||
const typeAliasNode = eslint_etc_1.getParent(functionTypeNode); | ||
if (allowLocal && !isExportNamedDeclaration(eslint_etc_1.getParent(typeAliasNode))) { | ||
if (allowLocal && | ||
!eslint_etc_1.isExportNamedDeclaration(eslint_etc_1.getParent(typeAliasNode))) { | ||
return; | ||
@@ -99,6 +91,6 @@ } | ||
for (const node of intersectionTypeNode.types) { | ||
if (isTSTypeLiteral(node)) { | ||
if (eslint_etc_1.isTSTypeLiteral(node)) { | ||
literals.push(node); | ||
} | ||
else if (isTSTypeReference(node)) { | ||
else if (eslint_etc_1.isTSTypeReference(node)) { | ||
references.push(node); | ||
@@ -150,3 +142,4 @@ } | ||
const typeAliasNode = eslint_etc_1.getParent(typeLiteralNode); | ||
if (allowLocal && !isExportNamedDeclaration(eslint_etc_1.getParent(typeAliasNode))) { | ||
if (allowLocal && | ||
!eslint_etc_1.isExportNamedDeclaration(eslint_etc_1.getParent(typeAliasNode))) { | ||
return; | ||
@@ -153,0 +146,0 @@ } |
@@ -60,3 +60,4 @@ "use strict"; | ||
ThrowStatement: (node) => { | ||
if (!isAny(node.argument) && | ||
if (node.argument && | ||
!isAny(node.argument) && | ||
!couldBeType(node.argument, /^(Error|DOMException)$/)) { | ||
@@ -63,0 +64,0 @@ context.report({ |
@@ -21,7 +21,11 @@ "use strict"; | ||
const { name } = parent; | ||
taggedNames.add(name.text); | ||
if (name === null || name === void 0 ? void 0 : name.text) { | ||
taggedNames.add(name.text); | ||
} | ||
} | ||
else { | ||
const { name } = node; | ||
taggedNames.add(name.text); | ||
if (name === null || name === void 0 ? void 0 : name.text) { | ||
taggedNames.add(name.text); | ||
} | ||
} | ||
@@ -28,0 +32,0 @@ }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getTag = exports.isDeclaration = void 0; | ||
exports.getTags = exports.isDeclaration = void 0; | ||
const tsutils = require("tsutils"); | ||
@@ -55,7 +55,7 @@ const ts = require("typescript"); | ||
} | ||
function getTag(tagName, node, tc) { | ||
function getTags(tagName, node, tc) { | ||
const callExpression = getCallExpresion(node); | ||
if (callExpression !== undefined) { | ||
const result = getSignatureTag(tagName, tc.getResolvedSignature(callExpression)); | ||
if (result !== undefined) { | ||
const result = getSignatureTags(tagName, tc.getResolvedSignature(callExpression)); | ||
if (result.length > 0) { | ||
return result; | ||
@@ -84,35 +84,36 @@ } | ||
(callExpression !== undefined && isFunctionOrMethod(symbol.declarations))) { | ||
return undefined; | ||
return []; | ||
} | ||
return getSymbolTag(tagName, symbol); | ||
return getSymbolTags(tagName, symbol); | ||
} | ||
exports.getTag = getTag; | ||
function findTag(tagName, tags) { | ||
exports.getTags = getTags; | ||
function findTags(tagName, tags) { | ||
const result = []; | ||
for (const tag of tags) { | ||
if (tag.name === tagName) { | ||
return tag.text === undefined ? "" : tag.text; | ||
result.push(tag.text === undefined ? "" : tag.text); | ||
} | ||
} | ||
return undefined; | ||
return result; | ||
} | ||
function getSymbolTag(tagName, symbol) { | ||
function getSymbolTags(tagName, symbol) { | ||
if (symbol.getJsDocTags !== undefined) { | ||
return findTag(tagName, symbol.getJsDocTags()); | ||
return findTags(tagName, symbol.getJsDocTags()); | ||
} | ||
return getDeprecationFromDeclarations(tagName, symbol.declarations); | ||
return getDeprecationsFromDeclarations(tagName, symbol.declarations); | ||
} | ||
function getSignatureTag(tagName, signature) { | ||
function getSignatureTags(tagName, signature) { | ||
if (signature === undefined) { | ||
return undefined; | ||
return []; | ||
} | ||
if (signature.getJsDocTags !== undefined) { | ||
return findTag(tagName, signature.getJsDocTags()); | ||
return findTags(tagName, signature.getJsDocTags()); | ||
} | ||
return signature.declaration === undefined | ||
? undefined | ||
: getDeprecationFromDeclaration(tagName, signature.declaration); | ||
? [] | ||
: getDeprecationsFromDeclaration(tagName, signature.declaration); | ||
} | ||
function getDeprecationFromDeclarations(tagName, declarations) { | ||
function getDeprecationsFromDeclarations(tagName, declarations) { | ||
if (declarations === undefined) { | ||
return undefined; | ||
return []; | ||
} | ||
@@ -130,10 +131,11 @@ let declaration; | ||
} | ||
const result = getDeprecationFromDeclaration(tagName, declaration); | ||
if (result !== undefined) { | ||
const result = getDeprecationsFromDeclaration(tagName, declaration); | ||
if (result.length > 0) { | ||
return result; | ||
} | ||
} | ||
return undefined; | ||
return []; | ||
} | ||
function getDeprecationFromDeclaration(tagName, declaration) { | ||
function getDeprecationsFromDeclaration(tagName, declaration) { | ||
const result = []; | ||
for (const comment of tsutils.getJsDoc(declaration)) { | ||
@@ -145,7 +147,7 @@ if (comment.tags === undefined) { | ||
if (tag.tagName.text === tagName) { | ||
return tag.comment === undefined ? "" : tag.comment; | ||
result.push(tag.comment === undefined ? "" : tag.comment); | ||
} | ||
} | ||
} | ||
return undefined; | ||
return result; | ||
} | ||
@@ -152,0 +154,0 @@ function isFunctionOrMethod(declarations) { |
@@ -81,3 +81,3 @@ { | ||
}, | ||
"version": "1.3.5" | ||
"version": "1.3.6" | ||
} |
78714
1286