Skip to content

test(eslint-plugin): add missing test cases for rules #1402

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

Merged
merged 14 commits into from
Jan 5, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/eslint-plugin/src/rules/class-name-casing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ export default util.createRule<Options, MessageIds>({
* @param decl The declaration
* @param id The name of the declaration
*/
function report(decl: TSESTree.Node, id: TSESTree.Identifier): void {
function report(
decl:
| TSESTree.ClassDeclaration
| TSESTree.TSInterfaceDeclaration
| TSESTree.ClassExpression,
id: TSESTree.Identifier,
): void {
let friendlyName;

switch (decl.type) {
Expand All @@ -78,8 +84,6 @@ export default util.createRule<Options, MessageIds>({
case AST_NODE_TYPES.TSInterfaceDeclaration:
friendlyName = 'Interface';
break;
default:
friendlyName = decl.type;
}

context.report({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export default util.createRule<Options, MessageIds>({

/**
* Checks that the parameter property has the desired accessibility modifiers set.
* @param {TSESTree.TSParameterProperty} node The node representing a Parameter Property
* @param node The node representing a Parameter Property
*/
function checkParameterPropertyAccessibilityModifier(
node: TSESTree.TSParameterProperty,
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-array-constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default util.createRule({
},
fixable: 'code',
messages: {
useLiteral: 'The array literal notation [] is preferrable.',
useLiteral: 'The array literal notation [] is preferable.',
},
schema: [],
},
Expand Down
30 changes: 11 additions & 19 deletions packages/eslint-plugin/src/rules/no-empty-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,25 @@ export default util.createRule<Options, MessageIds>({
return;
}

if (!node.extends || node.extends.length === 0) {
const extend = node.extends;
if (!extend || extend.length === 0) {
context.report({
node: node.id,
messageId: 'noEmpty',
});
} else if (node.extends.length === 1) {
} else if (extend.length === 1) {
// interface extends exactly 1 interface --> Report depending on rule setting
if (allowSingleExtends) {
return;
} else {
if (!allowSingleExtends) {
context.report({
node: node.id,
messageId: 'noEmptyWithSuper',
fix(fixer) {
if (node.extends && node.extends.length) {
return [
fixer.replaceText(
node,
`type ${sourceCode.getText(
node.id,
)} = ${sourceCode.getText(node.extends[0])}`,
),
];
}

return null;
},
fix: fixer =>
fixer.replaceText(
node,
`type ${sourceCode.getText(node.id)} = ${sourceCode.getText(
extend[0],
)}`,
),
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin/src/rules/no-misused-new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default util.createRule({
defaultOptions: [],
create(context) {
/**
* @param {ASTNode} node type to be inspected.
* @param node type to be inspected.
* @returns name of simple type or null
*/
function getTypeReferenceName(
Expand All @@ -48,8 +48,8 @@ export default util.createRule({
}

/**
* @param {ASTNode} parent parent node.
* @param {ASTNode} returnType type to be compared
* @param parent parent node.
* @param returnType type to be compared
*/
function isMatchingParentType(
parent: undefined | TSESTree.Node,
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin/src/rules/no-type-alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ export default util.createRule<Options, MessageIds>({

/**
* Validates the node looking for aliases, callbacks and literals.
* @param node the node to be validated.
* @param compositionType the type of composition this alias is part of (null if not
* @param type the type of composition this alias is part of (null if not
* part of a composition)
* @param isTopLevel a flag indicating this is the top level node.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export default util.createRule<Options, MessageIds>({
node: TSESTree.TSTypeAssertion | TSESTree.TSAsExpression,
): void {
if (
options?.typesToIgnore?.includes(
options.typesToIgnore?.includes(
sourceCode.getText(node.typeAnnotation),
)
) {
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin/tests/fixtures/class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// used by no-throw-literal test case to validate custom error
export class Error {}
Loading