-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lint): add deprecation warning regarding incorrect direct import…
…s for `attr`, `prop`, `jsonAttr`, `boolAttr`, `listen`
- Loading branch information
Showing
4 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type * as ESTree from 'estree'; | ||
import type {Rule} from 'eslint'; | ||
|
||
const meta: Rule.RuleModule['meta'] = { | ||
type: 'suggestion', | ||
docs: { | ||
description: 'replace deprecated path with a recommend one or use the library root & tree shaking', | ||
recommended: true | ||
} | ||
}; | ||
|
||
export interface ESLintDeprecationImportCfg { | ||
/** Alias name */ | ||
alias: string; | ||
/** Deprecated name */ | ||
deprecationPath: string; | ||
/** Recommended path */ | ||
recommendedPath: string; | ||
} | ||
|
||
type ImportNode = ESTree.ImportSpecifier & Rule.NodeParentExtension; | ||
|
||
/** Builds deprecation rule from {@link ESLintDeprecationCfg} object */ | ||
export function buildRule(configs: ESLintDeprecationImportCfg | ESLintDeprecationImportCfg[]): Rule.RuleModule { | ||
configs = Array.isArray(configs) ? configs : [configs]; | ||
const create = (context: Rule.RuleContext): Rule.RuleListener => ({ | ||
ImportSpecifier(node: ImportNode): null { | ||
const importedValue = node.imported; | ||
const importedSource = (node.parent as ESTree.ImportDeclaration).source.value; | ||
|
||
for (const cfg of configs) { | ||
if (importedValue.name === cfg.alias && importedSource === cfg.deprecationPath) { | ||
context.report({ | ||
node, | ||
message: `[ESL Lint]: Deprecated path for ${cfg.alias}, use ${cfg.recommendedPath} instead` | ||
}); | ||
} | ||
} | ||
return null; | ||
} | ||
}); | ||
return {meta, create}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import {buildRule} from '../../core/deprecated-path'; | ||
|
||
/** | ||
* Rule for deprecated `@exadel/esl/modules/esl-base-element/core` path to import {@link attr}, originally from `@exadel/esl/modules/esl-utils/decorators/attr`. | ||
*/ | ||
export default buildRule([ | ||
{ | ||
alias: 'attr', | ||
deprecationPath: '@exadel/esl/modules/esl-base-element/core', | ||
recommendedPath: '@exadel/esl/modules/esl-utils/decorators' | ||
}, | ||
{ | ||
alias: 'prop', | ||
deprecationPath: '@exadel/esl/modules/esl-base-element/core', | ||
recommendedPath: '@exadel/esl/modules/esl-utils/decorators' | ||
}, | ||
{ | ||
alias: 'boolAttr', | ||
deprecationPath: '@exadel/esl/modules/esl-base-element/core', | ||
recommendedPath: '@exadel/esl/modules/esl-utils/decorators' | ||
}, | ||
{ | ||
alias: 'jsonAttr', | ||
deprecationPath: '@exadel/esl/modules/esl-base-element/core', | ||
recommendedPath: '@exadel/esl/modules/esl-utils/decorators' | ||
}, | ||
{ | ||
alias: 'listen', | ||
deprecationPath: '@exadel/esl/modules/esl-base-element/core', | ||
recommendedPath: '@exadel/esl/modules/esl-utils/decorators' | ||
}, | ||
{ | ||
alias: 'attr', | ||
deprecationPath: '@exadel/esl/modules/esl-mixin-element/core', | ||
recommendedPath: '@exadel/esl/modules/esl-utils/decorators' | ||
}, | ||
{ | ||
alias: 'prop', | ||
deprecationPath: '@exadel/esl/modules/esl-mixin-element/core', | ||
recommendedPath: '@exadel/esl/modules/esl-utils/decorators' | ||
}, | ||
{ | ||
alias: 'boolAttr', | ||
deprecationPath: '@exadel/esl/modules/esl-mixin-element/core', | ||
recommendedPath: '@exadel/esl/modules/esl-utils/decorators' | ||
}, | ||
{ | ||
alias: 'jsonAttr', | ||
deprecationPath: '@exadel/esl/modules/esl-mixin-element/core', | ||
recommendedPath: '@exadel/esl/modules/esl-utils/decorators' | ||
}, | ||
{ | ||
alias: 'listen', | ||
deprecationPath: '@exadel/esl/modules/esl-mixin-element/core', | ||
recommendedPath: '@exadel/esl/modules/esl-utils/decorators' | ||
} | ||
]); |