Skip to content

Commit 0cc4d09

Browse files
committed
Init rule & add basic tests
1 parent 3db7b13 commit 0cc4d09

File tree

3 files changed

+182
-0
lines changed

3 files changed

+182
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This rule warns about the usage of extra whitespaces between attributes (no-extra-space-between-attributes)
2+
3+
Please describe the origin of the rule here.
4+
5+
6+
## Rule Details
7+
8+
This rule aims to...
9+
10+
Examples of **incorrect** code for this rule:
11+
12+
```js
13+
14+
// fill me in
15+
16+
```
17+
18+
Examples of **correct** code for this rule:
19+
20+
```js
21+
22+
// fill me in
23+
24+
```
25+
26+
### Options
27+
28+
If there are any options, describe them here. Otherwise, delete this section.
29+
30+
## When Not To Use It
31+
32+
Give a short description of when it would be appropriate to turn off this rule.
33+
34+
## Further Reading
35+
36+
If there are other links that describe the issue this rule addresses, please include them here in a bulleted list.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @fileoverview This rule warns about the usage of extra whitespaces between attributes
3+
* @author Armano
4+
*/
5+
'use strict'
6+
7+
// ------------------------------------------------------------------------------
8+
// Rule Definition
9+
// ------------------------------------------------------------------------------
10+
11+
module.exports = {
12+
meta: {
13+
docs: {
14+
description: 'This rule warns about the usage of extra whitespaces between attributes',
15+
category: 'Stylistic Issues',
16+
recommended: false
17+
},
18+
fixable: 'whitespace', // or "code" or "whitespace"
19+
schema: [
20+
// fill in your schema
21+
]
22+
},
23+
24+
create (context) {
25+
// variables should be defined here
26+
27+
// ----------------------------------------------------------------------
28+
// Helpers
29+
// ----------------------------------------------------------------------
30+
31+
// any helper functions should go here or else delete this section
32+
33+
// ----------------------------------------------------------------------
34+
// Public
35+
// ----------------------------------------------------------------------
36+
37+
return {
38+
// give me methods
39+
}
40+
}
41+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* @fileoverview This rule warns about the usage of extra whitespaces between attributes
3+
* @author Armano
4+
*/
5+
'use strict'
6+
7+
// ------------------------------------------------------------------------------
8+
// Requirements
9+
// ------------------------------------------------------------------------------
10+
11+
const rule = require('../../../lib/rules/no-extra-space-between-attributes')
12+
const RuleTester = require('eslint').RuleTester
13+
14+
// ------------------------------------------------------------------------------
15+
// Tests
16+
// ------------------------------------------------------------------------------
17+
18+
const ruleTester = new RuleTester({
19+
parser: 'vue-eslint-parser',
20+
parserOptions: { ecmaVersion: 2015 }
21+
})
22+
23+
ruleTester.run('no-extra-space-between-attributes', rule, {
24+
valid: [
25+
{
26+
filename: 'test.vue',
27+
code: `
28+
<template>
29+
<div></div>
30+
<div />
31+
<div class="foo"></div>
32+
<div class="foo" @click="bar"></div>
33+
<div class="foo"></div>
34+
<div class="foo"
35+
:style="foo"></div>
36+
<div class="foo"
37+
:style="foo"
38+
></div>
39+
<div class="foo"
40+
:style="foo" />
41+
</template>
42+
`
43+
}
44+
],
45+
46+
invalid: [
47+
{
48+
code: '<template><div /></template>',
49+
output: '<template><div /></template>',
50+
errors: [{
51+
message: 'Extra whitespace detected.',
52+
type: 'VText'
53+
}]
54+
},
55+
{
56+
code: '<template><div class="foo" /></template>',
57+
output: '<template><div class="foo" /></template>',
58+
errors: [{
59+
message: 'Extra whitespace detected.',
60+
type: 'VText'
61+
}, {
62+
message: 'Extra whitespace detected.',
63+
type: 'VText'
64+
}]
65+
},
66+
{
67+
code: '<template><div :class="foo" /></template>',
68+
output: '<template><div :class="foo" /></template>',
69+
errors: [{
70+
message: 'Extra whitespace detected.',
71+
type: 'VText'
72+
}, {
73+
message: 'Extra whitespace detected.',
74+
type: 'VText'
75+
}]
76+
},
77+
{
78+
code: '<template><div foo="" class="foo" /></template>',
79+
output: '<template><div foo="" class="foo" /></template>',
80+
errors: [{
81+
message: 'Extra whitespace detected.',
82+
type: 'VText'
83+
}]
84+
},
85+
{
86+
code: '<template><div v-foo="" class="foo" /></template>',
87+
output: '<template><div v-foo="" class="foo" /></template>',
88+
errors: [{
89+
message: 'Extra whitespace detected.',
90+
type: 'VText'
91+
}]
92+
},
93+
{
94+
code: '<template><div v-foo="" \n class="foo" /></template>',
95+
output: '<template><div v-foo=""\n class="foo" /></template>',
96+
errors: [{
97+
message: 'Extra whitespace detected.',
98+
type: 'VText'
99+
}, {
100+
message: 'Extra whitespace detected.',
101+
type: 'VText'
102+
}]
103+
}
104+
]
105+
})

0 commit comments

Comments
 (0)