Files
Umbraco-CMS/src/Umbraco.Web.UI.Client/eslint-local-rules.cjs
Jacob Overgaard a74f9886f8 import types
2022-08-25 15:58:27 +02:00

37 lines
1.1 KiB
JavaScript

'use strict';
/*
* A eslint rule that ensures the use of the `import type` operator from the `src/core/models/index.ts` file.
*/
// eslint-disable-next-line no-undef
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
'bad-type-import': {
meta: {
type: 'problem',
docs: {
description: 'Ensures the use of the `import type` operator from the `src/core/models/index.ts` file.',
category: 'Best Practices',
recommended: true,
},
fixable: 'code',
schema: [],
},
create: function (context) {
return {
ImportDeclaration: function (node) {
if (node.source.parent.importKind !== 'type' && (node.source.value.endsWith('/models') || node.source.value.endsWith('/generated-schema') || node.source.value === 'router-slot/model')) {
const sourceCode = context.getSourceCode();
const nodeSource = sourceCode.getText(node);
context.report({
node,
message: 'Use `import type` instead of `import`.',
fix: fixer => fixer.replaceText(node, nodeSource.replace('import', 'import type')),
});
}
},
};
}
}
};