forked from vuejs/eslint-plugin-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenforce-style-attribute.js
101 lines (98 loc) · 2.55 KB
/
enforce-style-attribute.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* @author Mussin Benarbia
* See LICENSE file in root directory for full license.
*/
'use strict'
const RuleTester = require('eslint').RuleTester
const rule = require('../../../lib/rules/enforce-style-attribute')
const tester = new RuleTester({
parser: require.resolve('vue-eslint-parser'),
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module'
}
})
tester.run('enforce-style-attribute', rule, {
valid: [
// With default options
{
filename: 'test.vue',
code: '<template></template><script></script><style scoped></style>'
},
{
filename: 'test.vue',
code: '<template></template><script></script><style module></style>'
},
{
filename: 'test.vue',
code: '<template></template><script></script><style lang=scss" "src="../path/to/style.scss" scoped></style>'
},
// With scoped option
{
filename: 'test.vue',
code: '<template></template><script></script><style scoped></style>',
options: ['scoped']
},
{
filename: 'test.vue',
code: '<template></template><script></script><style lang=scss" "src="../path/to/style.scss" scoped></style>',
options: ['scoped']
},
// With module option
{
filename: 'test.vue',
code: '<template></template><script></script><style module></style>',
options: ['module']
}
],
invalid: [
// With default options
{
code: `<template></template><script></script><style></style>`,
errors: [
{
message:
'The <style> tag should have either the scoped or module attribute.'
}
]
},
// With scoped option
{
code: `<template></template><script></script><style></style>`,
errors: [
{
message: 'The <style> tag should have the scoped attribute.'
}
],
options: ['scoped']
},
{
code: `<template></template><script></script><style module></style>`,
errors: [
{
message: 'The <style> tag should have the scoped attribute.'
}
],
options: ['scoped']
},
// With module option
{
code: `<template></template><script></script><style></style>`,
errors: [
{
message: 'The <style> tag should have the module attribute.'
}
],
options: ['module']
},
{
code: `<template></template><script></script><style scoped></style>`,
errors: [
{
message: 'The <style> tag should have the module attribute.'
}
],
options: ['module']
}
]
})