1 | # eslint-plugin-ember
|
2 |
|
3 | [![NPM version](https://img.shields.io/npm/v/eslint-plugin-ember.svg?style=flat)](https://npmjs.org/package/eslint-plugin-ember)
|
4 | [![NPM downloads](https://img.shields.io/npm/dm/eslint-plugin-ember.svg?style=flat)](https://npmjs.org/package/eslint-plugin-ember)
|
5 | ![CI](https://github.com/ember-cli/eslint-plugin-ember/workflows/CI/badge.svg)
|
6 |
|
7 | > An ESlint plugin that provides set of rules for Ember Applications based on commonly known good practices.
|
8 |
|
9 | ## βοΈRequirements
|
10 |
|
11 | - [ESLint](https://eslint.org/) `>= 6`
|
12 | - [Node.js](https://nodejs.org/) `10.* || 12.* || >= 14`
|
13 |
|
14 | ## π Usage
|
15 |
|
16 | ### 1. Install plugin
|
17 |
|
18 | ```shell
|
19 | yarn add --dev eslint-plugin-ember
|
20 | ```
|
21 |
|
22 | Or
|
23 |
|
24 | ```shell
|
25 | npm install --save-dev eslint-plugin-ember
|
26 | ```
|
27 |
|
28 | ### 2. Modify your `.eslintrc.js`
|
29 |
|
30 | ```js
|
31 | // .eslintrc.js
|
32 | module.exports = {
|
33 | plugins: ['ember'],
|
34 | extends: [
|
35 | 'eslint:recommended',
|
36 | 'plugin:ember/recommended' // or other configuration
|
37 | ],
|
38 | rules: {
|
39 | // override rule settings here
|
40 | 'ember/no-jquery': 'error'
|
41 | }
|
42 | };
|
43 | ```
|
44 |
|
45 | ## π§° Configurations
|
46 |
|
47 | | | Name | Description |
|
48 | |:---|:-----|:------------|
|
49 | | | [base](./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. |
|
50 | | β
| [recommended](./lib/recommended-rules.js) | extends the `base` configuration by enabling the recommended rules. |
|
51 |
|
52 | ## π Rules
|
53 |
|
54 | Rules are grouped by category to help you understand their purpose. Each rule has emojis denoting:
|
55 |
|
56 | - What configuration it belongs to
|
57 | - π§ if some problems reported by the rule are automatically fixable by the `--fix` [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) option
|
58 | - π‘ if some problems reported by the rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
|
59 |
|
60 |
|
61 |
|
62 | ### Components
|
63 |
|
64 | | Name | Description | β
| π§ | π‘ |
|
65 | |:--------|:------------|:---------------|:-----------|:---------------|
|
66 | | [no-attrs-in-components](./docs/rules/no-attrs-in-components.md) | disallow usage of `this.attrs` in components | β
| | |
|
67 | | [no-attrs-snapshot](./docs/rules/no-attrs-snapshot.md) | disallow use of attrs snapshot in the `didReceiveAttrs` and `didUpdateAttrs` component hooks | β
| | |
|
68 | | [no-classic-components](./docs/rules/no-classic-components.md) | enforce using Glimmer components | β
| | |
|
69 | | [no-component-lifecycle-hooks](./docs/rules/no-component-lifecycle-hooks.md) | disallow usage of "classic" ember component lifecycle hooks. Render modifiers or custom functional modifiers should be used instead. | β
| | |
|
70 | | [no-on-calls-in-components](./docs/rules/no-on-calls-in-components.md) | disallow usage of `on` to call lifecycle hooks in components | β
| | |
|
71 | | [require-tagless-components](./docs/rules/require-tagless-components.md) | disallow using the wrapper element of a component | β
| | |
|
72 |
|
73 | ### Computed Properties
|
74 |
|
75 | | Name | Description | β
| π§ | π‘ |
|
76 | |:--------|:------------|:---------------|:-----------|:---------------|
|
77 | | [computed-property-getters](./docs/rules/computed-property-getters.md) | enforce the consistent use of getters in computed properties | | | |
|
78 | | [no-arrow-function-computed-properties](./docs/rules/no-arrow-function-computed-properties.md) | disallow arrow functions in computed properties | β
| | |
|
79 | | [no-assignment-of-untracked-properties-used-in-tracking-contexts](./docs/rules/no-assignment-of-untracked-properties-used-in-tracking-contexts.md) | disallow assignment of untracked properties that are used as computed property dependencies | β
| π§ | |
|
80 | | [no-computed-properties-in-native-classes](./docs/rules/no-computed-properties-in-native-classes.md) | disallow using computed properties in native classes | β
| | |
|
81 | | [no-deeply-nested-dependent-keys-with-each](./docs/rules/no-deeply-nested-dependent-keys-with-each.md) | disallow usage of deeply-nested computed property dependent keys with `@each` | β
| | |
|
82 | | [no-duplicate-dependent-keys](./docs/rules/no-duplicate-dependent-keys.md) | disallow repeating computed property dependent keys | β
| π§ | |
|
83 | | [no-incorrect-computed-macros](./docs/rules/no-incorrect-computed-macros.md) | disallow incorrect usage of computed property macros | β
| π§ | |
|
84 | | [no-invalid-dependent-keys](./docs/rules/no-invalid-dependent-keys.md) | disallow invalid dependent keys in computed properties | β
| π§ | |
|
85 | | [no-side-effects](./docs/rules/no-side-effects.md) | disallow unexpected side effects in computed properties | β
| | |
|
86 | | [no-volatile-computed-properties](./docs/rules/no-volatile-computed-properties.md) | disallow volatile computed properties | β
| | |
|
87 | | [require-computed-macros](./docs/rules/require-computed-macros.md) | require using computed property macros when possible | β
| π§ | |
|
88 | | [require-computed-property-dependencies](./docs/rules/require-computed-property-dependencies.md) | require dependencies to be declared statically in computed properties | β
| π§ | |
|
89 | | [require-return-from-computed](./docs/rules/require-return-from-computed.md) | disallow missing return statements in computed properties | β
| | |
|
90 | | [use-brace-expansion](./docs/rules/use-brace-expansion.md) | enforce usage of brace expansion in computed property dependent keys | β
| | |
|
91 |
|
92 | ### Controllers
|
93 |
|
94 | | Name | Description | β
| π§ | π‘ |
|
95 | |:--------|:------------|:---------------|:-----------|:---------------|
|
96 | | [alias-model-in-controller](./docs/rules/alias-model-in-controller.md) | enforce aliasing model in controllers | | | |
|
97 | | [avoid-using-needs-in-controllers](./docs/rules/avoid-using-needs-in-controllers.md) | disallow using `needs` in controllers | β
| | |
|
98 | | [no-controllers](./docs/rules/no-controllers.md) | disallow non-essential controllers | | | |
|
99 |
|
100 | ### Deprecations
|
101 |
|
102 | | Name | Description | β
| π§ | π‘ |
|
103 | |:--------|:------------|:---------------|:-----------|:---------------|
|
104 | | [closure-actions](./docs/rules/closure-actions.md) | enforce usage of closure actions | β
| | |
|
105 | | [new-module-imports](./docs/rules/new-module-imports.md) | enforce using "New Module Imports" from Ember RFC #176 | β
| | |
|
106 | | [no-function-prototype-extensions](./docs/rules/no-function-prototype-extensions.md) | disallow usage of Ember's `function` prototype extensions | β
| | |
|
107 | | [no-mixins](./docs/rules/no-mixins.md) | disallow the usage of mixins | β
| | |
|
108 | | [no-new-mixins](./docs/rules/no-new-mixins.md) | disallow the creation of new mixins | β
| | |
|
109 | | [no-observers](./docs/rules/no-observers.md) | disallow usage of observers | β
| | |
|
110 | | [no-old-shims](./docs/rules/no-old-shims.md) | disallow usage of old shims for modules | β
| π§ | |
|
111 | | [no-string-prototype-extensions](./docs/rules/no-string-prototype-extensions.md) | disallow usage of `String` prototype extensions | β
| | |
|
112 |
|
113 | ### Ember Data
|
114 |
|
115 | | Name | Description | β
| π§ | π‘ |
|
116 | |:--------|:------------|:---------------|:-----------|:---------------|
|
117 | | [no-empty-attrs](./docs/rules/no-empty-attrs.md) | disallow usage of empty attributes in Ember Data models | | | |
|
118 | | [use-ember-data-rfc-395-imports](./docs/rules/use-ember-data-rfc-395-imports.md) | enforce usage of `@ember-data/` package imports instead `ember-data` | β
| π§ | |
|
119 |
|
120 | ### Ember Object
|
121 |
|
122 | | Name | Description | β
| π§ | π‘ |
|
123 | |:--------|:------------|:---------------|:-----------|:---------------|
|
124 | | [avoid-leaking-state-in-ember-objects](./docs/rules/avoid-leaking-state-in-ember-objects.md) | disallow state leakage | β
| | |
|
125 | | [no-get-with-default](./docs/rules/no-get-with-default.md) | disallow usage of the Ember's `getWithDefault` function | β
| π§ | |
|
126 | | [no-get](./docs/rules/no-get.md) | require using ES5 getters instead of Ember's `get` / `getProperties` functions | β
| π§ | |
|
127 | | [no-proxies](./docs/rules/no-proxies.md) | disallow using array or object proxies | | | |
|
128 | | [no-try-invoke](./docs/rules/no-try-invoke.md) | disallow usage of the Ember's `tryInvoke` util | β
| | |
|
129 | | [require-super-in-lifecycle-hooks](./docs/rules/require-super-in-lifecycle-hooks.md) | require super to be called in lifecycle hooks | β
| π§ | |
|
130 | | [use-ember-get-and-set](./docs/rules/use-ember-get-and-set.md) | enforce usage of `Ember.get` and `Ember.set` | | π§ | |
|
131 |
|
132 | ### Ember Octane
|
133 |
|
134 | | Name | Description | β
| π§ | π‘ |
|
135 | |:--------|:------------|:---------------|:-----------|:---------------|
|
136 | | [classic-decorator-hooks](./docs/rules/classic-decorator-hooks.md) | enforce using correct hooks for both classic and non-classic classes | β
| | |
|
137 | | [classic-decorator-no-classic-methods](./docs/rules/classic-decorator-no-classic-methods.md) | disallow usage of classic APIs such as `get`/`set` in classes that aren't explicitly decorated with `@classic` | β
| | |
|
138 | | [no-actions-hash](./docs/rules/no-actions-hash.md) | disallow the actions hash in components, controllers, and routes | β
| | |
|
139 | | [no-classic-classes](./docs/rules/no-classic-classes.md) | disallow "classic" classes in favor of native JS classes | β
| | |
|
140 | | [no-ember-super-in-es-classes](./docs/rules/no-ember-super-in-es-classes.md) | disallow use of `this._super` in ES class methods | β
| π§ | |
|
141 | | [no-empty-glimmer-component-classes](./docs/rules/no-empty-glimmer-component-classes.md) | disallow empty backing classes for Glimmer components | β
| | |
|
142 |
|
143 | ### jQuery
|
144 |
|
145 | | Name | Description | β
| π§ | π‘ |
|
146 | |:--------|:------------|:---------------|:-----------|:---------------|
|
147 | | [jquery-ember-run](./docs/rules/jquery-ember-run.md) | disallow usage of jQuery without an Ember run loop | β
| | |
|
148 | | [no-global-jquery](./docs/rules/no-global-jquery.md) | disallow usage of global jQuery object | β
| | |
|
149 | | [no-jquery](./docs/rules/no-jquery.md) | disallow any usage of jQuery | β
| | |
|
150 |
|
151 | ### Miscellaneous
|
152 |
|
153 | | Name | Description | β
| π§ | π‘ |
|
154 | |:--------|:------------|:---------------|:-----------|:---------------|
|
155 | | [named-functions-in-promises](./docs/rules/named-functions-in-promises.md) | enforce usage of named functions in promises | | | |
|
156 | | [no-html-safe](./docs/rules/no-html-safe.md) | disallow the use of `htmlSafe` | | | |
|
157 | | [no-incorrect-calls-with-inline-anonymous-functions](./docs/rules/no-incorrect-calls-with-inline-anonymous-functions.md) | disallow inline anonymous functions as arguments to `debounce`, `once`, and `scheduleOnce` | β
| | |
|
158 | | [no-invalid-debug-function-arguments](./docs/rules/no-invalid-debug-function-arguments.md) | disallow usages of Ember's `assert()` / `warn()` / `deprecate()` functions that have the arguments passed in the wrong order. | β
| | |
|
159 | | [no-restricted-property-modifications](./docs/rules/no-restricted-property-modifications.md) | disallow modifying the specified properties | | π§ | |
|
160 | | [require-fetch-import](./docs/rules/require-fetch-import.md) | enforce explicit import for `fetch()` | | | |
|
161 |
|
162 | ### Routes
|
163 |
|
164 | | Name | Description | β
| π§ | π‘ |
|
165 | |:--------|:------------|:---------------|:-----------|:---------------|
|
166 | | [no-capital-letters-in-routes](./docs/rules/no-capital-letters-in-routes.md) | disallow routes with uppercased letters in router.js | β
| | |
|
167 | | [no-controller-access-in-routes](./docs/rules/no-controller-access-in-routes.md) | disallow routes from accessing the controller outside of setupController/resetController | β
| | |
|
168 | | [no-private-routing-service](./docs/rules/no-private-routing-service.md) | disallow injecting the private routing service | β
| | |
|
169 | | [no-shadow-route-definition](./docs/rules/no-shadow-route-definition.md) | enforce no route path definition shadowing | β
| | |
|
170 | | [no-unnecessary-index-route](./docs/rules/no-unnecessary-index-route.md) | disallow unnecessary `index` route definition | | | |
|
171 | | [no-unnecessary-route-path-option](./docs/rules/no-unnecessary-route-path-option.md) | disallow unnecessary usage of the route `path` option | β
| π§ | |
|
172 | | [route-path-style](./docs/rules/route-path-style.md) | enforce usage of kebab-case (instead of snake_case or camelCase) in route paths | | | π‘ |
|
173 | | [routes-segments-snake-case](./docs/rules/routes-segments-snake-case.md) | enforce usage of snake_cased dynamic segments in routes | β
| | |
|
174 |
|
175 | ### Services
|
176 |
|
177 | | Name | Description | β
| π§ | π‘ |
|
178 | |:--------|:------------|:---------------|:-----------|:---------------|
|
179 | | [no-implicit-service-injection-argument](./docs/rules/no-implicit-service-injection-argument.md) | disallow omitting the injected service name argument | | π§ | |
|
180 | | [no-restricted-service-injections](./docs/rules/no-restricted-service-injections.md) | disallow injecting certain services under certain paths | | | |
|
181 | | [no-unnecessary-service-injection-argument](./docs/rules/no-unnecessary-service-injection-argument.md) | disallow unnecessary argument when injecting services | | π§ | |
|
182 | | [no-unused-services](./docs/rules/no-unused-services.md) | disallow unused service injections (see rule doc for limitations) | | | π‘ |
|
183 |
|
184 | ### Stylistic Issues
|
185 |
|
186 | | Name | Description | β
| π§ | π‘ |
|
187 | |:--------|:------------|:---------------|:-----------|:---------------|
|
188 | | [order-in-components](./docs/rules/order-in-components.md) | enforce proper order of properties in components | | π§ | |
|
189 | | [order-in-controllers](./docs/rules/order-in-controllers.md) | enforce proper order of properties in controllers | | π§ | |
|
190 | | [order-in-models](./docs/rules/order-in-models.md) | enforce proper order of properties in models | | π§ | |
|
191 | | [order-in-routes](./docs/rules/order-in-routes.md) | enforce proper order of properties in routes | | π§ | |
|
192 |
|
193 | ### Testing
|
194 |
|
195 | | Name | Description | β
| π§ | π‘ |
|
196 | |:--------|:------------|:---------------|:-----------|:---------------|
|
197 | | [no-current-route-name](./docs/rules/no-current-route-name.md) | disallow usage of the `currentRouteName()` test helper | | | |
|
198 | | [no-ember-testing-in-module-scope](./docs/rules/no-ember-testing-in-module-scope.md) | disallow use of `Ember.testing` in module scope | β
| | |
|
199 | | [no-invalid-test-waiters](./docs/rules/no-invalid-test-waiters.md) | disallow incorrect usage of test waiter APIs | β
| | |
|
200 | | [no-legacy-test-waiters](./docs/rules/no-legacy-test-waiters.md) | disallow the use of the legacy test waiter APIs | β
| | |
|
201 | | [no-noop-setup-on-error-in-before](./docs/rules/no-noop-setup-on-error-in-before.md) | disallows using no-op setupOnerror in `before` or `beforeEach` | β
| π§ | |
|
202 | | [no-pause-test](./docs/rules/no-pause-test.md) | disallow usage of the `pauseTest` helper in tests | β
| | |
|
203 | | [no-replace-test-comments](./docs/rules/no-replace-test-comments.md) | disallow 'Replace this with your real tests' comments in test files | | | |
|
204 | | [no-restricted-resolver-tests](./docs/rules/no-restricted-resolver-tests.md) | disallow the use of patterns that use the restricted resolver in tests | β
| | |
|
205 | | [no-settled-after-test-helper](./docs/rules/no-settled-after-test-helper.md) | disallow usage of `await settled()` right after test helper that calls it internally | β
| π§ | |
|
206 | | [no-test-and-then](./docs/rules/no-test-and-then.md) | disallow usage of the `andThen` test wait helper | β
| | |
|
207 | | [no-test-import-export](./docs/rules/no-test-import-export.md) | disallow importing of "-test.js" in a test file and exporting from a test file | β
| | |
|
208 | | [no-test-module-for](./docs/rules/no-test-module-for.md) | disallow usage of `moduleFor`, `moduleForComponent`, etc | β
| | |
|
209 | | [no-test-support-import](./docs/rules/no-test-support-import.md) | disallow importing of "test-support" files in production code. | β
| | |
|
210 | | [no-test-this-render](./docs/rules/no-test-this-render.md) | disallow usage of the `this.render` in tests, recommending to use @ember/test-helpers' `render` instead. | β
| | |
|
211 | | [prefer-ember-test-helpers](./docs/rules/prefer-ember-test-helpers.md) | enforce usage of `@ember/test-helpers` methods over native window methods | β
| | |
|
212 | | [require-valid-css-selector-in-test-helpers](./docs/rules/require-valid-css-selector-in-test-helpers.md) | disallow using invalid CSS selectors in test helpers | β
| π§ | |
|
213 |
|
214 |
|
215 |
|
216 | For the simplified list of rules, [go here](./lib/index.js).
|
217 |
|
218 | ## π» Contribution Guide
|
219 |
|
220 | If you have any suggestions, ideas, or problems, feel free to [create an issue](https://github.com/ember-cli/eslint-plugin-ember/issues/new), but first please make sure your question does not repeat [previous ones](https://github.com/ember-cli/eslint-plugin-ember/issues).
|
221 |
|
222 | ### Creating a New Rule
|
223 |
|
224 | - [Create an issue](https://github.com/ember-cli/eslint-plugin-ember/issues/new) with a description of the proposed rule
|
225 | - Create files for the [new rule](https://eslint.org/docs/developer-guide/working-with-rules):
|
226 | - `lib/rules/new-rule.js` (implementation, see [no-proxies](lib/rules/no-proxies.js) for an example)
|
227 | - `docs/rules/new-rule.md` (documentation, start from the template -- [raw](https://raw.githubusercontent.com/ember-cli/eslint-plugin-ember/master/docs/rules/_TEMPLATE_.md), [rendered](docs/rules/_TEMPLATE_.md))
|
228 | - `tests/lib/rules/new-rule.js` (tests, see [no-proxies](tests/lib/rules/no-proxies.js) for an example)
|
229 | - Run `yarn update` to automatically update the README and other files (and re-run this if you change the rule name or description)
|
230 | - Make sure your changes will pass [CI](.travis.yml) by running:
|
231 | - `yarn test`
|
232 | - `yarn lint` (`yarn lint:js --fix` can fix many errors)
|
233 | - Create a PR and link the created issue in the description
|
234 |
|
235 | Note that new rules should not immediately be added to the [recommended](./lib/recommended-rules.js) configuration, as we only consider such breaking changes during major version updates.
|
236 |
|
237 | ## π License
|
238 |
|
239 | See the [LICENSE](LICENSE.md) file for license rights and limitations (MIT).
|