forked from eslint-community/eslint-plugin-eslint-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta-property-ordering.js
126 lines (113 loc) · 2.95 KB
/
meta-property-ordering.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* @fileoverview Enforces the order of meta properties
*/
'use strict';
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
const rule = require('../../../lib/rules/meta-property-ordering');
const RuleTester = require('eslint').RuleTester;
// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
ruleTester.run('test-case-property-ordering', rule, {
valid: [
`
module.exports = {
meta: {type, docs, fixable, schema, messages},
create() {},
};`,
`
module.exports = {
meta: {docs, schema, messages},
create() {},
};`,
`
module.exports = {
meta: {docs, messages, foo, bar},
create() {},
};`,
`
module.exports = {
meta: {
type: 'problem',
docs: {},
fixable: 'code',
hasSuggestions: true,
schema: [],
messages: {}
},
create() {},
};`,
{
code: `
module.exports = {
meta: {schema, docs, fixable},
create() {},
};`,
options: [['schema', 'docs']],
},
`
module.exports = {
meta: {},
create() {},
};`,
],
invalid: [
{
code: `
module.exports = {
meta: {
docs,
fixable,
type: 'problem',
},
create() {},
};`,
output: `
module.exports = {
meta: {
type: 'problem',
docs,
fixable,
},
create() {},
};`,
errors: [{ messageId: 'inconsistentOrder', data: { order: ['type', 'docs', 'fixable'].join(', ') } }],
},
{
code: `
module.exports = {
meta: {schema, fixable, type, docs},
create() {},
};`,
output: `
module.exports = {
meta: {type, docs, fixable, schema},
create() {},
};`,
errors: [
{ messageId: 'inconsistentOrder', data: { order: ['type', 'docs', 'fixable', 'schema'].join(', ') } },
{ messageId: 'inconsistentOrder', data: { order: ['type', 'docs', 'fixable', 'schema'].join(', ') } },
],
},
{
code: `
module.exports = {
meta: {fixable, fooooooooo, docs, type},
create() {},
};`,
output: `
module.exports = {
meta: {type, docs, fixable, fooooooooo},
create() {},
};`,
options: [['type', 'docs', 'fixable']],
errors: [
{ messageId: 'inconsistentOrder', data: { order: ['type', 'docs', 'fixable'].join(', ') } },
{ messageId: 'inconsistentOrder', data: { order: ['type', 'docs', 'fixable'].join(', ') } },
],
},
],
});