Skip to content

Commit ea23b22

Browse files
committed
chore: add tests and docs for no-deprecated-imports
1 parent 3b0463d commit ea23b22

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ These rules will help you avoid deprecated components, props, and classes. They
4747
- Prevent the use of events that have been removed from Vuetify ([`no-deprecated-events`])
4848
- Prevent the use of classes that have been removed from Vuetify ([`no-deprecated-classes`])
4949
- Prevent the use of the old theme class syntax ([`no-deprecated-colors`])
50+
- Prevent the use of deprecated import paths ([`no-deprecated-imports`])
5051

5152
### Grid system
5253

@@ -61,6 +62,7 @@ These rules are designed to help migrate to the new grid system in Vuetify v2. T
6162
[`no-deprecated-events`]: ./docs/rules/no-deprecated-events.md
6263
[`no-deprecated-classes`]: ./docs/rules/no-deprecated-classes.md
6364
[`no-deprecated-colors`]: ./docs/rules/no-deprecated-colors.md
65+
[`no-deprecated-imports`]: ./docs/rules/no-deprecated-imports.md
6466

6567

6668
## 💪 Supporting Vuetify

src/rules/no-deprecated-imports.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ module.exports = {
1212
create (context) {
1313
return {
1414
ImportDeclaration (node) {
15-
const source = node.source.value
16-
if (source === 'vuetify/lib/util/colors') {
15+
if (node.source.value === 'vuetify/lib/util/colors') {
1716
context.report({
1817
node,
1918
message: 'Import from "vuetify/lib/util/colors" is deprecated. Use "vuetify/util/colors" instead.',
2019
fix (fixer) {
21-
const fixedSource = source.replace('vuetify/lib/util/colors', 'vuetify/util/colors')
22-
return fixer.replaceText(node.source, `'${fixedSource}'`)
20+
return fixer.replaceText(
21+
node.source,
22+
node.source.raw.replace('vuetify/lib/util/colors', 'vuetify/util/colors')
23+
)
2324
},
2425
})
2526
}

tests/rules/no-deprecated-imports.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const RuleTester = require('eslint').RuleTester
2+
const rule = require('../../src/rules/no-deprecated-imports')
3+
4+
const tester = new RuleTester({
5+
parser: require.resolve('vue-eslint-parser'),
6+
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
7+
})
8+
9+
tester.run('no-deprecated-imports', rule, {
10+
valid: [
11+
'import colors from "vuetify/util/colors"',
12+
`import colors from 'vuetify/util/colors'`,
13+
],
14+
invalid: [
15+
{
16+
code: `import colors from 'vuetify/lib/util/colors'`,
17+
output: `import colors from 'vuetify/util/colors'`,
18+
errors: [{ message: 'Import from "vuetify/lib/util/colors" is deprecated. Use "vuetify/util/colors" instead.' }],
19+
},
20+
{
21+
code: `import colors from "vuetify/lib/util/colors"`,
22+
output: `import colors from "vuetify/util/colors"`,
23+
errors: [{ message: 'Import from "vuetify/lib/util/colors" is deprecated. Use "vuetify/util/colors" instead.' }],
24+
},
25+
],
26+
})

0 commit comments

Comments
 (0)