Skip to content

Commit 91ff6a6

Browse files
authored
refactor: rename rule (#5)
1 parent e235193 commit 91ff6a6

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

src/configs/recommended.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ export const name = 'recommended';
1414
export const config = {
1515
plugins: [pluginName],
1616
rules: {
17-
[`${pluginName}/no-inheritance`]: 'error',
17+
[`${pluginName}/no-class-inheritance`]: 'error',
1818
},
1919
};

src/rules/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as noInheritanceRule from './no-inheritance';
1+
import * as noClassInheritanceRule from './no-class-inheritance';
22

33
export const rules = {
4-
[noInheritanceRule.name]: noInheritanceRule.rule,
4+
[noClassInheritanceRule.name]: noClassInheritanceRule.rule,
55
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './class-type';
2+
export * from './no-class-inheritance';

src/rules/no-inheritance/no-inheritance.rule.spec.ts renamed to src/rules/no-class-inheritance/no-class-inheritance.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RuleTester } from '@typescript-eslint/rule-tester';
2-
import * as noInheritanceRule from './no-inheritance.rule';
2+
import * as noInheritanceRule from './no-class-inheritance';
33
import * as path from 'path';
44

55
describe('Rule', () => {
@@ -29,7 +29,7 @@ describe('Rule', () => {
2929
},
3030
{
3131
code: 'abstract class Parent {} class Child extends Parent {}',
32-
errors: [{ messageId: 'inheritanceNotAllowed' }],
32+
errors: [{ messageId: 'inheritanceOfAbstractClassesNotAllowed' }],
3333
options: [{ noInheritanceOfAbstractClasses: true }],
3434
},
3535
{

src/rules/no-inheritance/no-inheritance.rule.ts renamed to src/rules/no-class-inheritance/no-class-inheritance.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const createRule = ESLintUtils.RuleCreator(
99
/**
1010
* Rule name
1111
*/
12-
export const name = 'no-inheritance';
12+
export const name = 'no-class-inheritance';
1313

1414
/**
1515
* Options
@@ -36,9 +36,12 @@ const meta: NamedCreateRuleMeta<string, Options> = {
3636
description: 'Inheritance is not allowed.',
3737
},
3838
messages: {
39-
inheritanceNotAllowed: 'Inheritance is not allowed.',
39+
inheritanceNotAllowed:
40+
'Inheritance of non-abstract classes is not allowed. Consider using composition or extend abstract class',
41+
inheritanceOfAbstractClassesNotAllowed: 'Inheritance is not allowed',
4042
},
41-
type: 'problem',
43+
hasSuggestions: true,
44+
type: 'suggestion',
4245
schema: [
4346
{
4447
type: 'object',
@@ -72,13 +75,15 @@ export const rule = createRule({
7275
return;
7376
}
7477

75-
if (
76-
options[0]?.noInheritanceOfAbstractClasses ||
77-
!classType.inheritsOnlyAbstractClasses()
78-
) {
78+
if (options[0]?.noInheritanceOfAbstractClasses) {
79+
context.report({
80+
messageId: 'inheritanceOfAbstractClassesNotAllowed',
81+
loc: node.loc,
82+
});
83+
} else if (!classType.inheritsOnlyAbstractClasses()) {
7984
context.report({
8085
messageId: 'inheritanceNotAllowed',
81-
node,
86+
loc: node.loc,
8287
});
8388
}
8489
},

src/rules/no-inheritance/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)