-
-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathno-decorators-before-export.js
More file actions
70 lines (68 loc) · 2.75 KB
/
no-decorators-before-export.js
File metadata and controls
70 lines (68 loc) · 2.75 KB
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
const rule = require('../../../lib/rules/no-decorators-before-export');
const RuleTester = require('eslint').RuleTester;
const eslintTester = new RuleTester({
parser: require.resolve('@babel/eslint-parser'),
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
requireConfigFile: false,
babelOptions: {
babelrc: false,
plugins: [['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }]],
},
},
});
eslintTester.run('no-decorators-before-export', rule, {
valid: [
'export default class {}',
'export default class Foo {}',
'class Foo {}\nexport default Foo;',
'export class Foo {}',
'class Foo {}\nexport { Foo };',
"import classic from 'ember-classic-decorators';\n@classic\nclass Foo {}\nexport { Foo };",
"import classic from 'ember-classic-decorators';\n@classic\nclass Foo {}\nexport default Foo;",
],
invalid: [
// basic
{
code: "import classic from 'ember-classic-decorators';\n@classic\nexport class Foo {}",
output:
"import classic from 'ember-classic-decorators';\n@classic\nclass Foo {}\nexport { Foo };\n",
errors: [
'Usage of class decorator on the export Foo must occur prior to exporting the class.',
],
},
{
code: "import classic from 'ember-classic-decorators';\n@classic\nexport default class Foo {}",
output:
"import classic from 'ember-classic-decorators';\n@classic\nclass Foo {}\nexport default Foo;\n",
errors: [
'Usage of class decorator on the default export Foo must occur prior to exporting the class.',
],
},
{
code: "import classic from 'ember-classic-decorators';\n@classic\nexport default class {}",
output: null,
errors: [
'Usage of class decorator on the un-named default export must occur prior to exporting the class.',
],
},
// ensure interop
{
code: "import classic from 'ember-classic-decorators';\n@classic\nexport class Foo {\n someProp = false;\n}\nexport class Bar {};\n",
output:
"import classic from 'ember-classic-decorators';\n@classic\nclass Foo {\n someProp = false;\n}\nexport { Foo };\n\nexport class Bar {};\n",
errors: [
'Usage of class decorator on the export Foo must occur prior to exporting the class.',
],
},
{
code: "import classic from 'ember-classic-decorators';\n@classic\nexport default class Foo {\n someProp = false;\n}\nexport class Bar {};\n",
output:
"import classic from 'ember-classic-decorators';\n@classic\nclass Foo {\n someProp = false;\n}\nexport default Foo;\n\nexport class Bar {};\n",
errors: [
'Usage of class decorator on the default export Foo must occur prior to exporting the class.',
],
},
],
});