diff --git a/README.md b/README.md index 88ba2f1..d0e0e12 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ These rules will help you avoid deprecated components, props, and classes. They - Prevent the use of events that have been removed from Vuetify ([`no-deprecated-events`]) - Prevent the use of classes that have been removed from Vuetify ([`no-deprecated-classes`]) - Prevent the use of the old theme class syntax ([`no-deprecated-colors`]) +- Prevent the use of deprecated import paths ([`no-deprecated-imports`]) ### Grid system @@ -61,6 +62,7 @@ These rules are designed to help migrate to the new grid system in Vuetify v2. T [`no-deprecated-events`]: ./docs/rules/no-deprecated-events.md [`no-deprecated-classes`]: ./docs/rules/no-deprecated-classes.md [`no-deprecated-colors`]: ./docs/rules/no-deprecated-colors.md +[`no-deprecated-imports`]: ./docs/rules/no-deprecated-imports.md ## 💪 Supporting Vuetify diff --git a/src/rules/no-deprecated-imports.js b/src/rules/no-deprecated-imports.js index 33e9238..cf89ca0 100644 --- a/src/rules/no-deprecated-imports.js +++ b/src/rules/no-deprecated-imports.js @@ -12,14 +12,15 @@ module.exports = { create (context) { return { ImportDeclaration (node) { - const source = node.source.value - if (source === 'vuetify/lib/util/colors') { + if (node.source.value === 'vuetify/lib/util/colors') { context.report({ node, message: 'Import from "vuetify/lib/util/colors" is deprecated. Use "vuetify/util/colors" instead.', fix (fixer) { - const fixedSource = source.replace('vuetify/lib/util/colors', 'vuetify/util/colors') - return fixer.replaceText(node.source, `'${fixedSource}'`) + return fixer.replaceText( + node.source, + node.source.raw.replace('vuetify/lib/util/colors', 'vuetify/util/colors') + ) }, }) } diff --git a/tests/rules/no-deprecated-imports.js b/tests/rules/no-deprecated-imports.js new file mode 100644 index 0000000..ec687ed --- /dev/null +++ b/tests/rules/no-deprecated-imports.js @@ -0,0 +1,26 @@ +const RuleTester = require('eslint').RuleTester +const rule = require('../../src/rules/no-deprecated-imports') + +const tester = new RuleTester({ + parser: require.resolve('vue-eslint-parser'), + parserOptions: { ecmaVersion: 2015, sourceType: 'module' }, +}) + +tester.run('no-deprecated-imports', rule, { + valid: [ + 'import colors from "vuetify/util/colors"', + `import colors from 'vuetify/util/colors'`, + ], + invalid: [ + { + code: `import colors from 'vuetify/lib/util/colors'`, + output: `import colors from 'vuetify/util/colors'`, + errors: [{ message: 'Import from "vuetify/lib/util/colors" is deprecated. Use "vuetify/util/colors" instead.' }], + }, + { + code: `import colors from "vuetify/lib/util/colors"`, + output: `import colors from "vuetify/util/colors"`, + errors: [{ message: 'Import from "vuetify/lib/util/colors" is deprecated. Use "vuetify/util/colors" instead.' }], + }, + ], +})