Skip to content
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

refactor(eslint): restructure eslint module rules, simplify usage #2131

Merged
merged 1 commit into from
Dec 21, 2023
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
2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extends:
- 'eslint:recommended'
- 'plugin:import/typescript'
- 'plugin:@typescript-eslint/recommended'
- 'plugin:@exadel/esl/default-4'
- 'plugin:@exadel/esl/default'

# Library base set
- './linting/codestyle.eslintrc.yml'
Expand Down
32 changes: 9 additions & 23 deletions eslint/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
import deprecatedAlertActionParams from './rules/4/deprecated.alert-action-params';
import deprecatedGenerateUid from './rules/4/deprecated.generate-uid';
import deprecatedDeepCompare from './rules/4/deprecated.deep-compare';
import deprecatedEventUtils from './rules/4/deprecated.event-utils';
import deprecatedPanelActionParams from './rules/4/deprecated.panel-action-params';
import deprecatedPopupActionParams from './rules/4/deprecated.popup-action-params';
import deprecatedTraversingQuery from './rules/4/deprecated.traversing-query';
import deprecatedToggleableActionParams from './rules/4/deprecated.toggleable-action-params';
import deprecatedTooltipActionParams from './rules/4/deprecated.tooltip-action-params';
import DEPRECATED_4_RULES from './rules/4/all.rules';
import DEPRECATED_5_RULES from './rules/5/all.rules';

import type {Rule} from 'eslint';

export type logLevel = 'warn' | 'error';

const DEPRECATED_4_RULES = {
'deprecated-4/alert-action-params': deprecatedAlertActionParams,
'deprecated-4/generate-uid': deprecatedGenerateUid,
'deprecated-4/deep-compare': deprecatedDeepCompare,
'deprecated-4/event-utils': deprecatedEventUtils,
'deprecated-4/panel-action-params': deprecatedPanelActionParams,
'deprecated-4/popup-action-params': deprecatedPopupActionParams,
'deprecated-4/traversing-query': deprecatedTraversingQuery,
'deprecated-4/toggleable-action-params': deprecatedToggleableActionParams,
'deprecated-4/tooltip-action-params': deprecatedTooltipActionParams
};

const buildDefault = (definition: Record<string, Rule.RuleModule>, level: logLevel): Record<string, logLevel> => {
const config: Record<string, logLevel> = {};
for (const name of Object.keys(definition)) {
Expand All @@ -33,7 +14,7 @@ const buildDefault = (definition: Record<string, Rule.RuleModule>, level: logLev
return config;
};

export const rules = Object.assign({}, DEPRECATED_4_RULES);
export const rules = Object.assign({}, DEPRECATED_4_RULES, DEPRECATED_5_RULES);

export const configs = {
'default-4': {
Expand All @@ -43,7 +24,12 @@ export const configs = {
},
'default-5': {
rules: {
...buildDefault(DEPRECATED_4_RULES, 'error')
...buildDefault(DEPRECATED_5_RULES, 'warn')
}
abarmina marked this conversation as resolved.
Show resolved Hide resolved
},
'default': {
rules: {
...buildDefault(DEPRECATED_5_RULES, 'warn')
}
}
};
13 changes: 13 additions & 0 deletions eslint/src/rules/4/all.rules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import deprecatedGenerateUid from './deprecated.generate-uid';
import deprecatedDeepCompare from './deprecated.deep-compare';
import deprecatedEventUtils from './deprecated.event-utils';
import deprecatedTraversingQuery from './deprecated.traversing-query';
import deprecatedToggleableActionParams from './deprecated.toggleable-action-params';

export default {
'deprecated-4/generate-uid': deprecatedGenerateUid,
'deprecated-4/deep-compare': deprecatedDeepCompare,
'deprecated-4/event-utils': deprecatedEventUtils,
'deprecated-4/traversing-query': deprecatedTraversingQuery,
'deprecated-4/toggleable-action-params': deprecatedToggleableActionParams
};
11 changes: 11 additions & 0 deletions eslint/src/rules/5/all.rules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import deprecatedAlertActionParams from './deprecated.alert-action-params';
import deprecatedPanelActionParams from './deprecated.panel-action-params';
import deprecatedPopupActionParams from './deprecated.popup-action-params';
import deprecatedTooltipActionParams from './deprecated.tooltip-action-params';

export default {
'deprecated-5/alert-action-params': deprecatedAlertActionParams,
'deprecated-5/panel-action-params': deprecatedPanelActionParams,
'deprecated-5/popup-action-params': deprecatedPopupActionParams,
'deprecated-5/tooltip-action-params': deprecatedTooltipActionParams
};
Loading