UNPKG

18.1 kBMarkdownView Raw
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
19yarn add --dev eslint-plugin-ember
20```
21
22Or
23
24```shell
25npm install --save-dev eslint-plugin-ember
26```
27
28### 2. Modify your `.eslintrc.js`
29
30```js
31// .eslintrc.js
32module.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
54Rules 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<!--RULES_TABLE_START-->
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<!--RULES_TABLE_END-->
215
216For the simplified list of rules, [go here](./lib/index.js).
217
218## 🍻 Contribution Guide
219
220If 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
235Note 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
239See the [LICENSE](LICENSE.md) file for license rights and limitations (MIT).