Skip to content

Commit

Permalink
refactor: reorganize code (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsndr authored Apr 15, 2024
1 parent 7fb2760 commit 5d5baaa
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 28 deletions.
6 changes: 6 additions & 0 deletions src/configs/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import { readPackage } from './../helpers';
const pkg = readPackage();
const pluginName = pkg.name.replace('eslint-plugin-', '');

/**
* Name
*/
export const name = 'recommended';

/**
* Config
*/
export const config = {
plugins: [pluginName],
rules: {
Expand Down
9 changes: 9 additions & 0 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ import { readPackage } from './helpers';

const pkg = readPackage();

/**
* Plugin meta
*/
export const meta = {
name: pkg.name,
version: pkg.version,
};

/**
* Rules
*/
export { rules } from './rules';

/**
* Configs
*/
export { configs } from './configs';
2 changes: 1 addition & 1 deletion src/rules/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as noInheritanceRule from './no-inheritance.rule';
import * as noInheritanceRule from './no-inheritance';

export const rules = {
[noInheritanceRule.name]: noInheritanceRule.rule,
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/rules/no-inheritance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './class-type';
export * from './no-inheritance.rule';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Rule', () => {
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: path.resolve(__dirname, '../..'),
tsconfigRootDir: path.resolve(__dirname, '../../..'),
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,64 @@
import { ESLintUtils } from '@typescript-eslint/utils';
import { ClassType } from './class-type';
import { NamedCreateRuleMeta } from '@typescript-eslint/utils/eslint-utils';

const createRule = ESLintUtils.RuleCreator(
() => `https://github.com/lsndr/eslint-plugin-typescript-inheritance`,
);

/**
* Rule name
*/
export const name = 'no-inheritance';

/**
* Options
*/
type NoInheritanceOfAbstractClassesOptions = {
noInheritanceOfAbstractClasses: boolean;
};
type Options = [NoInheritanceOfAbstractClassesOptions];

/**
* Default Options
*/
const defaultOptions: Options = [
{
noInheritanceOfAbstractClasses: false,
},
];

/**
* Meta
*/
const meta: NamedCreateRuleMeta<string, Options> = {
docs: {
description: 'Inheritance is not allowed.',
},
messages: {
inheritanceNotAllowed: 'Inheritance is not allowed.',
},
type: 'problem',
schema: [
{
type: 'object',
properties: {
noInheritanceOfAbstractClasses: {
type: 'boolean',
},
},
additionalProperties: false,
},
],
};

/**
* Rule
*/
export const rule = createRule({
meta,
name,
defaultOptions,
create(context, options) {
return {
ClassDeclaration(node) {
Expand All @@ -33,30 +84,4 @@ export const rule = createRule({
},
};
},
meta: {
docs: {
description: 'Inheritance is not allowed.',
},
messages: {
inheritanceNotAllowed: 'Inheritance is not allowed.',
},
type: 'problem',
schema: [
{
type: 'object',
properties: {
noInheritanceOfAbstractClasses: {
type: 'boolean',
},
},
additionalProperties: false,
},
],
},
name,
defaultOptions: [
{
noInheritanceOfAbstractClasses: false,
},
],
});

0 comments on commit 5d5baaa

Please sign in to comment.