Skip to content

Commit

Permalink
chore: add tests and docs for no-deprecated-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
KaelWD committed Mar 10, 2024
1 parent 3b0463d commit ea23b22
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/rules/no-deprecated-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
)
},
})
}
Expand Down
26 changes: 26 additions & 0 deletions tests/rules/no-deprecated-imports.js
Original file line number Diff line number Diff line change
@@ -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.' }],
},
],
})

0 comments on commit ea23b22

Please sign in to comment.