12.0.2 • Published 2 months ago

eslint-plugin-ember v12.0.2

Weekly downloads
216,259
License
MIT
Repository
github
Last release
2 months ago

eslint-plugin-ember

NPM version NPM downloads CI

An ESLint plugin that provides a set of rules for Ember applications based on commonly known good practices.

❗️Requirements

🚀 Usage

1. Install plugin

yarn add --dev eslint-plugin-ember

Or

npm install --save-dev eslint-plugin-ember

2. Update your config

// eslint.config.js (flat config)
const eslintPluginEmberRecommended = require('eslint-plugin-ember/configs/recommended');

module.exports = [
  ...eslintPluginEmberRecommended,
];

or

// .eslintrc.js (legacy config)
module.exports = {
  plugins: ['ember'],
  extends: [
    'eslint:recommended',
    'plugin:ember/recommended' // or other configuration
  ],
  rules: {
    // override / enable optional rules
    'ember/no-replace-test-comments': 'error'
  }
};

gts/gjs

lint files having First-Class Component Templates (fcct)

learn more here

!NOTE special care should be used when setting up parsers, since they cannot be overwritten. thus they should be used in override only and specific to file types

gjs/gts support is provided by the ember-eslint-parser

!NOTE if you import .gts files in .ts files, then ember-eslint-parser is required for .ts as well to enable typed linting

// .eslintrc.js
module.exports = {
  overrides: [
    {
      files: ['**/*.{js,ts}'],
      plugins: ['ember'],
      parser: '@typescript-eslint/parser',
      extends: [
        'eslint:recommended',
        'plugin:ember/recommended', // or other configuration
      ],
      rules: {
        // override / enable optional rules
        'ember/no-replace-test-comments': 'error'
      }
    },
    {
      files: ['**/*.gts'],
      parser: 'ember-eslint-parser',
      plugins: ['ember'],
      extends: [
        'eslint:recommended',
        'plugin:@typescript-eslint/recommended',
        'plugin:ember/recommended',
        'plugin:ember/recommended-gts',
      ],
    },
    {
      files: ['**/*.gjs'],
      parser: 'ember-eslint-parser',
      plugins: ['ember'],
      extends: [
        'eslint:recommended',
        'plugin:ember/recommended',
        'plugin:ember/recommended-gjs',
      ],
    },
    {
      files: ['tests/**/*.{js,ts,gjs,gts}'],
      rules: {
        // override / enable optional rules
        'ember/no-replace-test-comments': 'error'
      }
    },
  ],
};

rules applied to fcct templates

  • semi rule, same as prettier plugin
  • no-undef rule will take effect for template vars (includes js scope)
  • no-unused rule will take effect for template block params

rules in templates can be disabled with eslint directives with mustache or html comments:

<template>
  <div>
    {{!eslint-disable-next-line}}
    {{test}}
  </div>
  <div>
    {{!--eslint-disable--}}
    {{test}}
    {{test}}
    {{test}}
    {{!--eslint-enable--}}
  </div>
</template>
<template>
  <div>
    <!--eslint-disable-next-line-->
    {{test}}
  </div>
  <div>
    <!-- eslint-disable -->
    {{test}}
    {{test}}
    {{test}}
    <!-- eslint-enable -->
  </div>
</template>

🧰 Configurations

Name
base
recommended
gjs logorecommended-gjs
gts logorecommended-gts

🍟 Rules

💼 Configurations enabled in.\ ✅ Set in the recommended configuration.\ gjs logo Set in the recommended-gjs configuration.\ gts logo Set in the recommended-gts configuration.\ 🔧 Automatically fixable by the --fix CLI option.\ 💡 Manually fixable by editor suggestions.

Components

Name                        Description💼🔧💡
no-attrs-in-componentsdisallow usage of this.attrs in components
no-attrs-snapshotdisallow use of attrs snapshot in the didReceiveAttrs and didUpdateAttrs component hooks
no-classic-componentsenforce using Glimmer components
no-component-lifecycle-hooksdisallow usage of "classic" ember component lifecycle hooks. Render modifiers or custom functional modifiers should be used instead.
no-on-calls-in-componentsdisallow usage of on to call lifecycle hooks in components
require-tagless-componentsdisallow using the wrapper element of a component

Computed Properties

Name                                                           Description💼🔧💡
computed-property-gettersenforce the consistent use of getters in computed properties
no-arrow-function-computed-propertiesdisallow arrow functions in computed properties
no-assignment-of-untracked-properties-used-in-tracking-contextsdisallow assignment of untracked properties that are used as computed property dependencies🔧
no-computed-properties-in-native-classesdisallow using computed properties in native classes
no-deeply-nested-dependent-keys-with-eachdisallow usage of deeply-nested computed property dependent keys with @each
no-duplicate-dependent-keysdisallow repeating computed property dependent keys🔧
no-incorrect-computed-macrosdisallow incorrect usage of computed property macros🔧
no-invalid-dependent-keysdisallow invalid dependent keys in computed properties🔧
no-side-effectsdisallow unexpected side effects in computed properties
no-volatile-computed-propertiesdisallow volatile computed properties
require-computed-macrosrequire using computed property macros when possible🔧
require-computed-property-dependenciesrequire dependencies to be declared statically in computed properties🔧
require-return-from-computeddisallow missing return statements in computed properties
use-brace-expansionenforce usage of brace expansion in computed property dependent keys

Controllers

NameDescription💼🔧💡
alias-model-in-controllerenforce aliasing model in controllers
avoid-using-needs-in-controllersdisallow using needs in controllers
no-controllersdisallow non-essential controllers

Deprecations

NameDescription💼🔧💡
closure-actionsenforce usage of closure actions
new-module-importsenforce using "New Module Imports" from Ember RFC #176
no-array-prototype-extensionsdisallow usage of Ember's Array prototype extensions🔧
no-at-ember-render-modifiersdisallow importing from @ember/render-modifiers
no-deprecated-router-transition-methodsenforce usage of router service transition methods🔧
no-function-prototype-extensionsdisallow usage of Ember's function prototype extensions
no-implicit-injectionsenforce usage of implicit service injections🔧
no-mixinsdisallow the usage of mixins
no-new-mixinsdisallow the creation of new mixins
no-observersdisallow usage of observers
no-old-shimsdisallow usage of old shims for modules🔧
no-string-prototype-extensionsdisallow usage of String prototype extensions

Ember Data

Name                          Description💼🔧💡
no-empty-attrsdisallow usage of empty attributes in Ember Data models
use-ember-data-rfc-395-importsenforce usage of @ember-data/ package imports instead ember-data🔧

Ember Object

Name                                Description💼🔧💡
avoid-leaking-state-in-ember-objectsdisallow state leakage
no-getrequire using ES5 getters instead of Ember's get / getProperties functions🔧
no-get-with-defaultdisallow usage of the Ember's getWithDefault function🔧
no-proxiesdisallow using array or object proxies
no-try-invokedisallow usage of the Ember's tryInvoke util
require-super-in-lifecycle-hooksrequire super to be called in lifecycle hooks🔧
use-ember-get-and-setenforce usage of Ember.get and Ember.set🔧

Ember Octane

Name                                Description💼🔧💡
classic-decorator-hooksenforce using correct hooks for both classic and non-classic classes
classic-decorator-no-classic-methodsdisallow usage of classic APIs such as get/set in classes that aren't explicitly decorated with @classic
no-actions-hashdisallow the actions hash in components, controllers, and routes
no-classic-classesdisallow "classic" classes in favor of native JS classes
no-ember-super-in-es-classesdisallow use of this._super in ES class methods🔧
no-empty-glimmer-component-classesdisallow empty backing classes for Glimmer components
no-tracked-properties-from-argsdisallow creating @tracked properties from this.args
template-indentenforce consistent indentation for gts/gjs templates🔧
template-no-let-referencedisallow referencing let variables in \<template>gjs logo gts logo

jQuery

NameDescription💼🔧💡
jquery-ember-rundisallow usage of jQuery without an Ember run loop
no-global-jquerydisallow usage of global jQuery object
no-jquerydisallow any usage of jQuery

Miscellaneous

Name                                              Description💼🔧💡
named-functions-in-promisesenforce usage of named functions in promises
no-html-safedisallow the use of htmlSafe
no-incorrect-calls-with-inline-anonymous-functionsdisallow inline anonymous functions as arguments to debounce, once, and scheduleOnce
no-invalid-debug-function-argumentsdisallow usages of Ember's assert() / warn() / deprecate() functions that have the arguments passed in the wrong order.
no-restricted-property-modificationsdisallow modifying the specified properties🔧
no-runloopdisallow usage of @ember/runloop functions
require-fetch-importenforce explicit import for fetch()

Routes

Name                            Description💼🔧💡
no-capital-letters-in-routesdisallow routes with uppercased letters in router.js
no-controller-access-in-routesdisallow routes from accessing the controller outside of setupController/resetController
no-private-routing-servicedisallow injecting the private routing service
no-shadow-route-definitionenforce no route path definition shadowing
no-unnecessary-index-routedisallow unnecessary index route definition
no-unnecessary-route-path-optiondisallow unnecessary usage of the route path option🔧
route-path-styleenforce usage of kebab-case (instead of snake_case or camelCase) in route paths💡
routes-segments-snake-caseenforce usage of snake_cased dynamic segments in routes

Services

Name                                     Description💼🔧💡
no-implicit-service-injection-argumentdisallow omitting the injected service name argument🔧
no-restricted-service-injectionsdisallow injecting certain services under certain paths
no-unnecessary-service-injection-argumentdisallow unnecessary argument when injecting services🔧
no-unused-servicesdisallow unused service injections (see rule doc for limitations)💡

Stylistic Issues

NameDescription💼🔧💡
order-in-componentsenforce proper order of properties in components🔧
order-in-controllersenforce proper order of properties in controllers🔧
order-in-modelsenforce proper order of properties in models🔧
order-in-routesenforce proper order of properties in routes🔧

Testing

Name                                      Description💼🔧💡
no-current-route-namedisallow usage of the currentRouteName() test helper
no-ember-testing-in-module-scopedisallow use of Ember.testing in module scope
no-invalid-test-waitersdisallow incorrect usage of test waiter APIs
no-legacy-test-waitersdisallow the use of the legacy test waiter APIs
no-noop-setup-on-error-in-beforedisallows using no-op setupOnerror in before or beforeEach🔧
no-pause-testdisallow usage of the pauseTest helper in tests
no-replace-test-commentsdisallow 'Replace this with your real tests' comments in test files
no-restricted-resolver-testsdisallow the use of patterns that use the restricted resolver in tests
no-settled-after-test-helperdisallow usage of await settled() right after test helper that calls it internally🔧
no-test-and-thendisallow usage of the andThen test wait helper
no-test-import-exportdisallow importing of "-test.js" in a test file and exporting from a test file
no-test-module-fordisallow usage of moduleFor, moduleForComponent, etc
no-test-support-importdisallow importing of "test-support" files in production code.
no-test-this-renderdisallow usage of the this.render in tests, recommending to use @ember/test-helpers' render instead.
prefer-ember-test-helpersenforce usage of @ember/test-helpers methods over native window methods
require-valid-css-selector-in-test-helpersdisallow using invalid CSS selectors in test helpers🔧

🍻 Contribution Guide

If you have any suggestions, ideas, or problems, feel free to create an issue, but first please make sure your question does not repeat previous ones.

Creating a New Rule

  • Create an issue with a description of the proposed rule
  • Create files for the new rule:
    • lib/rules/new-rule.js (implementation, see no-proxies for an example)
    • docs/rules/new-rule.md (documentation, start from the template -- raw, rendered)
    • tests/lib/rules/new-rule.js (tests, see no-proxies for an example)
  • Run yarn update to automatically update the README and other files (and re-run this if you change the rule name or description)
  • Make sure your changes will pass CI by running:
    • yarn test
    • yarn lint (yarn lint:js --fix can fix many errors)
  • Create a PR and link the created issue in the description

Note that new rules should not immediately be added to the recommended configuration, as we only consider such breaking changes during major version updates.

🔓 License

See the LICENSE file for license rights and limitations (MIT).

12.0.2

2 months ago

12.0.1

2 months ago

12.0.0

3 months ago

12.0.0-alpha.4

4 months ago

11.12.0

5 months ago

12.0.0-alpha.3

5 months ago

12.0.0-alpha.1

6 months ago

12.0.0-alpha.0

6 months ago

12.0.0-alpha.2

6 months ago

11.11.1

8 months ago

11.11.0

8 months ago

11.9.0

10 months ago

11.10.0

10 months ago

11.8.0

11 months ago

11.6.0

12 months ago

11.7.0

11 months ago

11.7.1

11 months ago

11.7.2

11 months ago

11.5.2

1 year ago

11.5.1

1 year ago

11.5.0

1 year ago

11.4.8

1 year ago

11.4.9

1 year ago

11.4.7

1 year ago

11.4.3

1 year ago

11.4.6

1 year ago

11.4.4

1 year ago

11.4.5

1 year ago

11.2.0

1 year ago

11.2.1

1 year ago

11.1.0

2 years ago

11.4.2

1 year ago

11.4.0

1 year ago

11.4.1

1 year ago

11.3.1

1 year ago

11.3.0

1 year ago

11.0.6

2 years ago

11.0.4

2 years ago

11.0.5

2 years ago

11.0.2

2 years ago

11.0.3

2 years ago

11.0.0

2 years ago

11.0.1

2 years ago

10.6.1

2 years ago

10.6.0

2 years ago

10.5.9

2 years ago

10.5.8

2 years ago

10.5.7

3 years ago

10.5.6

3 years ago

10.5.5

3 years ago

10.5.4

3 years ago

10.5.2

3 years ago

10.5.3

3 years ago

10.5.1

3 years ago

10.5.0

3 years ago

10.4.1

3 years ago

10.4.2

3 years ago

10.4.0

3 years ago

10.3.0

3 years ago

10.2.0

3 years ago

10.1.2

3 years ago

10.1.1

3 years ago

10.1.0

3 years ago

10.0.2

3 years ago

10.0.1

3 years ago

10.0.0

3 years ago

9.6.0

3 years ago

9.5.0

3 years ago

9.4.0

3 years ago

9.3.0

4 years ago

9.2.0

4 years ago

9.1.1

4 years ago

9.1.0

4 years ago

9.0.0

4 years ago

8.14.0

4 years ago

8.13.0

4 years ago

8.12.0

4 years ago

8.11.0

4 years ago

8.10.1

4 years ago

8.10.0

4 years ago

8.9.2

4 years ago

8.9.1

4 years ago

8.9.0

4 years ago

8.8.0

4 years ago

8.7.0

4 years ago

8.6.0

4 years ago

8.5.2

4 years ago

8.5.1

4 years ago

8.5.0

4 years ago

8.4.0

4 years ago

8.3.0

4 years ago

8.2.0

4 years ago

8.1.1

4 years ago

8.1.0

4 years ago

8.0.0

4 years ago

7.13.0

4 years ago

7.12.0

4 years ago

7.11.1

4 years ago

7.11.0

4 years ago

7.10.1

4 years ago

7.10.0

4 years ago

7.9.0

4 years ago

7.8.1

4 years ago

7.8.0

4 years ago

7.7.2

4 years ago

7.7.1

4 years ago

7.7.0

4 years ago

7.6.0

4 years ago

7.5.0

4 years ago

7.4.1

4 years ago

7.4.0

4 years ago

7.3.0

4 years ago

7.2.0

5 years ago

7.1.0

5 years ago

7.0.0

5 years ago

6.10.1

5 years ago

6.10.0

5 years ago

6.9.1

5 years ago

6.9.0

5 years ago

6.8.2

5 years ago

6.8.1

5 years ago

6.8.0

5 years ago

6.7.1

5 years ago

6.7.0

5 years ago

6.6.0

5 years ago

6.5.1

5 years ago

6.5.0

5 years ago

6.4.1

5 years ago

6.4.0

5 years ago

6.3.0

5 years ago

6.2.0

5 years ago

6.1.0

5 years ago

6.0.1

5 years ago

6.0.0

5 years ago

5.4.0

5 years ago

5.3.0

5 years ago

5.2.0

6 years ago

5.1.1

6 years ago

5.1.0

6 years ago

5.0.3

6 years ago

5.0.2

6 years ago

5.0.1

6 years ago

5.0.0

6 years ago

4.6.2

6 years ago

5.0.0-beta.2

6 years ago

5.0.0-beta.1

6 years ago

4.6.1

6 years ago

4.6.0

6 years ago

4.5.0

7 years ago

4.4.0

7 years ago

4.3.0

7 years ago

4.2.0

7 years ago

4.1.3

7 years ago

4.1.2

7 years ago

4.1.1

7 years ago

4.1.0

7 years ago

4.0.0

7 years ago

3.6.2

7 years ago

3.6.1

7 years ago

3.6.0

7 years ago

3.5.0

7 years ago

3.4.1

7 years ago

3.4.0

7 years ago

3.3.0

7 years ago

3.2.0

7 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.2.2

7 years ago

2.2.1

7 years ago

2.2.0

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.0

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago