Skip to content

Commit 3c8959e

Browse files
authored
Merge pull request #561 from patocallaghan/patoc/octane-configuration
Add `octane` configuration (experimental)
2 parents 5bae106 + cd57425 commit 3c8959e

18 files changed

+84
-11
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
coverage/
22
node_modules
33
lib/recommended-rules.js
4+
lib/octane-rules.js

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib/octane-rules.js
2+
lib/recommended-rules.js

README.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ module.exports = {
4646
Possible configurations:
4747
- [plugin:ember/base](https://github.com/ember-cli/eslint-plugin-ember/blob/master/lib/config/base.js) - contains no rules settings, but the basic eslint configuration suitable for any ember project. You can use it to configure rules as you wish.
4848
- [plugin:ember/recommended](https://github.com/ember-cli/eslint-plugin-ember/blob/master/lib/config/recommended.js) - extends base configuration with recommended rules' settings
49+
- :warning: [plugin:ember/octane](https://github.com/ember-cli/eslint-plugin-ember/blob/master/lib/config/octane.js) - extends recommended configuration with octane rules' settings. This ruleset is currently considered **unstable and experiemental** as rules may be added and removed until the final ruleset is settled upon.
4950

5051
#### Use plain plugin:
5152

@@ -74,6 +75,8 @@ Rules are grouped by category to help you understand their purpose.
7475

7576
All rules below with a check mark :white_check_mark: are enabled by default while using `plugin:ember/recommended` config.
7677

78+
The `plugin:ember/octane` config contains both Octane rules with a red car :car: in addition to the rules in the `plugin:ember/recommended` config.
79+
7780
The `--fix` option on the command line automatically fixes problems reported by rules which have a wrench :wrench: below.
7881

7982
<!--RULES_TABLE_START-->
@@ -88,9 +91,9 @@ The `--fix` option on the command line automatically fixes problems reported by
8891
| | [named-functions-in-promises](./docs/rules/named-functions-in-promises.md) | Enforces usage of named functions in promises |
8992
| :white_check_mark: | [new-module-imports](./docs/rules/new-module-imports.md) | Use "New Module Imports" from Ember RFC #176 |
9093
| :white_check_mark: | [no-function-prototype-extensions](./docs/rules/no-function-prototype-extensions.md) | Prevents usage of Ember's `function` prototype extensions |
91-
| | [no-get](./docs/rules/no-get.md) | Require ES5 getters instead of Ember's `get` / `getProperties` functions |
94+
| :car: | [no-get](./docs/rules/no-get.md) | Require ES5 getters instead of Ember's `get` / `getProperties` functions |
9295
| :white_check_mark: | [no-global-jquery](./docs/rules/no-global-jquery.md) | Prevents usage of global jQuery object |
93-
| | [no-jquery](./docs/rules/no-jquery.md) | Disallow any usage of jQuery |
96+
| :car: | [no-jquery](./docs/rules/no-jquery.md) | Disallow any usage of jQuery |
9497
| :white_check_mark: | [no-new-mixins](./docs/rules/no-new-mixins.md) | Prevents creation of new mixins |
9598
| :white_check_mark: | [no-observers](./docs/rules/no-observers.md) | Prevents usage of observers |
9699
| :white_check_mark::wrench: | [no-old-shims](./docs/rules/no-old-shims.md) | Prevents usage of old shims for modules |
@@ -110,8 +113,8 @@ The `--fix` option on the command line automatically fixes problems reported by
110113
| | Rule ID | Description |
111114
|:---|:--------|:------------|
112115
| :white_check_mark: | [avoid-leaking-state-in-ember-objects](./docs/rules/avoid-leaking-state-in-ember-objects.md) | Avoids state leakage |
113-
| | [classic-decorator-hooks](./docs/rules/classic-decorator-hooks.md) | Ensure correct hooks are used for both classic and non-classic classes |
114-
| | [classic-decorator-no-classic-methods](./docs/rules/classic-decorator-no-classic-methods.md) | Prevent usage of classic APIs such as get/set in classes that aren't explicitly decorated with @classic |
116+
| :car: | [classic-decorator-hooks](./docs/rules/classic-decorator-hooks.md) | Ensure correct hooks are used for both classic and non-classic classes |
117+
| :car: | [classic-decorator-no-classic-methods](./docs/rules/classic-decorator-no-classic-methods.md) | Prevent usage of classic APIs such as get/set in classes that aren't explicitly decorated with @classic |
115118
| | [computed-property-getters](./docs/rules/computed-property-getters.md) | Enforce the consistent use of getters in computed properties |
116119
| | [no-proxies](./docs/rules/no-proxies.md) | Disallows using array or object proxies |
117120

@@ -142,11 +145,11 @@ The `--fix` option on the command line automatically fixes problems reported by
142145

143146
| | Rule ID | Description |
144147
|:---|:--------|:------------|
145-
| | [no-actions-hash](./docs/rules/no-actions-hash.md) | Disallows the actions hash in components, controllers and routes |
146-
| | [no-classic-classes](./docs/rules/no-classic-classes.md) | Disallow "classic" classes in favor of native JS classes |
147-
| | [no-classic-components](./docs/rules/no-classic-components.md) | Enforces Glimmer components |
148-
| | [no-computed-properties-in-native-classes](./docs/rules/no-computed-properties-in-native-classes.md) | Disallows using computed properties in native classes |
149-
| | [require-tagless-components](./docs/rules/require-tagless-components.md) | Disallows using the wrapper element of a Component |
148+
| :car: | [no-actions-hash](./docs/rules/no-actions-hash.md) | Disallows the actions hash in components, controllers and routes |
149+
| :car: | [no-classic-classes](./docs/rules/no-classic-classes.md) | Disallow "classic" classes in favor of native JS classes |
150+
| :car: | [no-classic-components](./docs/rules/no-classic-components.md) | Enforces Glimmer components |
151+
| :car: | [no-computed-properties-in-native-classes](./docs/rules/no-computed-properties-in-native-classes.md) | Disallows using computed properties in native classes |
152+
| :car: | [require-tagless-components](./docs/rules/require-tagless-components.md) | Disallows using the wrapper element of a Component |
150153

151154

152155
### Ember Data

lib/config/octane.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const rules = require('../octane-rules.js');
2+
3+
module.exports = {
4+
extends: require.resolve('./recommended.js'),
5+
rules,
6+
};

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ module.exports = {
6464
configs: {
6565
base: require('./config/base'),
6666
recommended: require('./config/recommended'),
67+
octane: require('./config/octane'),
6768
},
6869
utils: {
6970
ember: require('./utils/ember'),

lib/octane-rules.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* IMPORTANT!
3+
* This file has been automatically generated.
4+
* In order to update its content based on rules'
5+
* definitions, execute "npm run update"
6+
*/
7+
module.exports = {
8+
"ember/classic-decorator-hooks": "error",
9+
"ember/classic-decorator-no-classic-methods": "error",
10+
"ember/no-actions-hash": "error",
11+
"ember/no-classic-classes": "error",
12+
"ember/no-classic-components": "error",
13+
"ember/no-computed-properties-in-native-classes": "error",
14+
"ember/no-get": "error",
15+
"ember/no-jquery": "error",
16+
"ember/require-tagless-components": "error"
17+
}

lib/rules/classic-decorator-hooks.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
description: 'Ensure correct hooks are used for both classic and non-classic classes',
1616
category: 'Ember Object',
1717
recommended: false,
18+
octane: true,
1819
url:
1920
'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/classic-decorator-hooks.md',
2021
},

lib/rules/classic-decorator-no-classic-methods.js

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module.exports = {
2727
"Prevent usage of classic APIs such as get/set in classes that aren't explicitly decorated with @classic",
2828
category: 'Ember Object',
2929
recommended: false,
30+
octane: true,
3031
url:
3132
'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/classic-decorator-no-classic-methods.md',
3233
},

lib/rules/no-actions-hash.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
description: 'Disallows the actions hash in components, controllers and routes',
1111
category: 'Ember Octane',
1212
recommended: false,
13+
octane: true,
1314
},
1415
fixable: null, // or "code" or "whitespace"
1516
url:

lib/rules/no-classic-classes.js

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = {
2626
description: 'Disallow "classic" classes in favor of native JS classes',
2727
category: 'Ember Octane',
2828
recommended: false,
29+
octane: true,
2930
},
3031
fixable: null, // or "code" or "whitespace"
3132
},

lib/rules/no-classic-components.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
description: 'Enforces Glimmer components',
1010
category: 'Ember Octane',
1111
recommended: false,
12+
octane: true,
1213
url:
1314
'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/no-classic-components.md',
1415
},

lib/rules/no-computed-properties-in-native-classes.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = {
3131
description: 'Disallows using computed properties in native classes',
3232
category: 'Ember Octane',
3333
recommended: false,
34+
octane: true,
3435
url:
3536
'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/no-computed-properties-in-native-classes.md',
3637
},

lib/rules/no-get.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = {
1919
description: "Require ES5 getters instead of Ember's `get` / `getProperties` functions",
2020
category: 'Best Practices',
2121
recommended: false,
22+
octane: true,
2223
},
2324
schema: [
2425
{

lib/rules/no-jquery.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
description: 'Disallow any usage of jQuery',
1818
category: 'Best Practices',
1919
recommended: false,
20+
octane: true,
2021
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/no-jquery.md',
2122
},
2223
fixable: null, // or "code" or "whitespace"

lib/rules/require-tagless-components.js

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ module.exports = {
9292
description: 'Disallows using the wrapper element of a Component',
9393
category: 'Ember Octane',
9494
recommended: false,
95+
octane: true,
9596
url:
9697
'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/require-tagless-components.md',
9798
},

scripts/update-rules.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ const path = require('path');
2121
const root = path.resolve(__dirname, '../lib/rules');
2222
const readmeFile = path.resolve(__dirname, '../README.md');
2323
const recommendedRulesFile = path.resolve(__dirname, '../lib/recommended-rules.js');
24+
const octaneRulesFile = path.resolve(__dirname, '../lib/octane-rules.js');
2425
const tablePlaceholder = /<!--RULES_TABLE_START-->[\s\S]*<!--RULES_TABLE_END-->/;
2526
const readmeContent = fs.readFileSync(readmeFile, 'utf8');
2627

2728
const STAR = ':white_check_mark:';
2829
const PEN = ':wrench:';
30+
const OCTANE = ':car:';
2931

3032
const rules = fs
3133
.readdirSync(root)
@@ -54,7 +56,9 @@ ${rules
5456
.map(entry => {
5557
const name = entry[0];
5658
const meta = entry[1].meta;
57-
const mark = `${meta.docs.recommended ? STAR : ''}${meta.fixable ? PEN : ''}`;
59+
const mark = `${meta.docs.recommended ? STAR : ''}${meta.docs.octane ? OCTANE : ''}${
60+
meta.fixable ? PEN : ''
61+
}`;
5862
const link = `[${name}](./docs/rules/${name}.md)`;
5963
const description = meta.docs.description || '(no description)';
6064
return `| ${mark} | ${link} | ${description} |`;
@@ -112,3 +116,22 @@ fs.writeFileSync(
112116
);
113117

114118
fs.writeFileSync(recommendedRulesFile, recommendedRulesContent);
119+
120+
const octaneRules = rules.reduce((obj, entry) => {
121+
const name = `ember/${entry[0]}`;
122+
const octane = entry[1].meta.docs.octane;
123+
if (octane) {
124+
obj[name] = 'error'; // eslint-disable-line no-param-reassign
125+
}
126+
return obj;
127+
}, {});
128+
129+
const octaneRulesContent = `/*
130+
* IMPORTANT!
131+
* This file has been automatically generated.
132+
* In order to update its content based on rules'
133+
* definitions, execute "npm run update"
134+
*/
135+
module.exports = ${JSON.stringify(octaneRules, null, 2)}`;
136+
137+
fs.writeFileSync(octaneRulesFile, octaneRulesContent);

tests/plugin-exports.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const ember = require('../lib/utils/ember');
66
const utils = require('../lib/utils/utils');
77
const base = require('../lib/config/base.js');
88
const recommended = require('../lib/config/recommended.js');
9+
const octane = require('../lib/config/octane.js');
910

1011
describe('plugin exports', () => {
1112
describe('utils', () => {
@@ -16,7 +17,7 @@ describe('plugin exports', () => {
1617

1718
describe('configs', () => {
1819
it('has the right configurations', () => {
19-
assert.deepStrictEqual(plugin.configs, { base, recommended });
20+
assert.deepStrictEqual(plugin.configs, { base, recommended, octane });
2021
});
2122
});
2223
});

tests/rule-setup.js

+10
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ const { join } = require('path');
55
const assert = require('assert');
66
const rules = require('../lib/index.js').rules;
77
const recommendedRules = require('../lib/recommended-rules.js');
8+
const octaneRules = require('../lib/octane-rules.js');
89

910
const RULE_NAMES = Object.keys(rules);
11+
const OCTANE_RULE_NAMES = Object.keys(octaneRules);
1012

1113
describe('rules setup is correct', function() {
1214
it('should have a list of exported rules and rules directory that match', function() {
@@ -27,6 +29,14 @@ describe('rules setup is correct', function() {
2729
);
2830
});
2931

32+
it('should list all rules in the octane rules file', function() {
33+
const octaneRuleNames = Object.keys(rules).filter(key => rules[key].meta.docs.octane);
34+
assert.deepStrictEqual(
35+
OCTANE_RULE_NAMES.map(file => file.replace('ember/', '')),
36+
octaneRuleNames
37+
);
38+
});
39+
3040
it('should have tests for all rules', function() {
3141
const path = join(__dirname, '../tests/lib/rules');
3242
const files = readdirSync(path);

0 commit comments

Comments
 (0)