What is eslint-plugin-ember?
eslint-plugin-ember is an ESLint plugin that provides linting rules specific to Ember.js applications. It helps developers follow best practices and maintain consistency in their Ember.js codebase.
What are eslint-plugin-ember's main functionalities?
Best Practices
This rule enforces the best practice of avoiding the use of observers in Ember.js applications. Observers can lead to unpredictable behavior and are generally discouraged.
module.exports = {
rules: {
'ember/no-observers': 'error'
}
};
Stylistic Issues
This rule ensures that developers use Ember's `get` and `set` methods for property access and assignment, which is a stylistic convention in Ember.js.
module.exports = {
rules: {
'ember/use-ember-get-and-set': 'error'
}
};
Ember-Specific Rules
This rule disallows the use of jQuery in Ember.js applications, encouraging developers to use native DOM APIs or Ember's own abstractions.
module.exports = {
rules: {
'ember/no-jquery': 'error'
}
};
Other packages similar to eslint-plugin-ember
eslint-plugin-react
eslint-plugin-react provides linting rules for React applications. It helps enforce best practices and coding standards specific to React, similar to how eslint-plugin-ember does for Ember.js.
eslint-plugin-vue
eslint-plugin-vue offers linting rules for Vue.js applications. It ensures that Vue.js code adheres to best practices and stylistic conventions, much like eslint-plugin-ember does for Ember.js.
eslint-plugin-angular
eslint-plugin-angular provides linting rules for Angular applications. It helps maintain code quality and consistency in Angular projects, similar to the role of eslint-plugin-ember in Ember.js projects.
eslint-plugin-ember
An ESLint plugin that provides a set of rules for Ember applications based on commonly known good practices.
❗️Requirements
🚀 Usage
1. Install plugin
npm install --save-dev eslint-plugin-ember
2. Update your config
const eslintPluginEmberRecommended = require('eslint-plugin-ember/configs/recommended');
module.exports = [
...eslintPluginEmberRecommended,
];
or
module.exports = {
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
],
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
module.exports = {
overrides: [
{
files: ['**/*.{js,ts}'],
plugins: ['ember'],
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
'plugin:ember/recommended',
],
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: {
'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 |
| recommended-gjs |
| recommended-gts |
🍟 Rules
💼 Configurations enabled in.
✅ Set in the recommended
configuration.
Set in the recommended-gjs
configuration.
Set in the recommended-gts
configuration.
🔧 Automatically fixable by the --fix
CLI option.
💡 Manually fixable by editor suggestions.
Components
Computed Properties
Controllers
Deprecations
Ember Data
Ember Object
Ember Octane
jQuery
Miscellaneous
Routes
Services
Stylistic Issues
Testing
🍻 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
pnpm 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:
pnpm test
pnpm lint
(pnpm 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).