An ESLint plugin that provides a set of rules for Ember applications based on commonly known good practices.
yarn add --dev eslint-plugin-ember
Or
npm install --save-dev eslint-plugin-ember
.eslintrc.js
// .eslintrc.js
module.exports = {
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/recommended' // or other configuration
],
rules: {
// override rule settings here
'ember/no-jquery': 'error'
}
};
Name | Description | |
---|---|---|
base | contains no rules settings, but the basic eslint configuration suitable for any ember project. You can use it to configure rules as you wish. | |
|
recommended | extends the base configuration by enabling the recommended rules. |
Rules are grouped by category to help you understand their purpose. Each rule has emojis denoting:
--fix
command line optionName | Description |
|
|
|
---|---|---|---|---|
no-attrs-in-components | disallow usage of this.attrs in components |
|
||
no-attrs-snapshot | disallow use of attrs snapshot in the didReceiveAttrs and didUpdateAttrs component hooks |
|
||
no-classic-components | enforce using Glimmer components |
|
||
no-component-lifecycle-hooks | disallow usage of "classic" ember component lifecycle hooks. Render modifiers or custom functional modifiers should be used instead. |
|
||
no-on-calls-in-components | disallow usage of on to call lifecycle hooks in components |
|
||
require-tagless-components | disallow using the wrapper element of a component |
|
Name | Description |
|
|
|
---|---|---|---|---|
computed-property-getters | enforce the consistent use of getters in computed properties | |||
no-arrow-function-computed-properties | disallow arrow functions in computed properties |
|
||
no-assignment-of-untracked-properties-used-in-tracking-contexts | disallow assignment of untracked properties that are used as computed property dependencies |
|
|
|
no-computed-properties-in-native-classes | disallow using computed properties in native classes |
|
||
no-deeply-nested-dependent-keys-with-each | disallow usage of deeply-nested computed property dependent keys with @each |
|
||
no-duplicate-dependent-keys | disallow repeating computed property dependent keys |
|
|
|
no-incorrect-computed-macros | disallow incorrect usage of computed property macros |
|
|
|
no-invalid-dependent-keys | disallow invalid dependent keys in computed properties |
|
|
|
no-side-effects | disallow unexpected side effects in computed properties |
|
||
no-volatile-computed-properties | disallow volatile computed properties |
|
||
require-computed-macros | require using computed property macros when possible |
|
|
|
require-computed-property-dependencies | require dependencies to be declared statically in computed properties |
|
|
|
require-return-from-computed | disallow missing return statements in computed properties |
|
||
use-brace-expansion | enforce usage of brace expansion in computed property dependent keys |
|
Name | Description |
|
|
|
---|---|---|---|---|
alias-model-in-controller | enforce aliasing model in controllers | |||
avoid-using-needs-in-controllers | disallow using needs in controllers |
|
||
no-controllers | disallow non-essential controllers |
Name | Description |
|
|
|
---|---|---|---|---|
closure-actions | enforce usage of closure actions |
|
||
new-module-imports | enforce using "New Module Imports" from Ember RFC #176 |
|
||
no-function-prototype-extensions | disallow usage of Ember's function prototype extensions |
|
||
no-mixins | disallow the usage of mixins |
|
||
no-new-mixins | disallow the creation of new mixins |
|
||
no-observers | disallow usage of observers |
|
||
no-old-shims | disallow usage of old shims for modules |
|
|
|
no-string-prototype-extensions | disallow usage of String prototype extensions |
|
Name | Description |
|
|
|
---|---|---|---|---|
no-empty-attrs | disallow usage of empty attributes in Ember Data models | |||
use-ember-data-rfc-395-imports | enforce usage of @ember-data/ package imports instead ember-data |
|
|
Name | Description |
|
|
|
---|---|---|---|---|
avoid-leaking-state-in-ember-objects | disallow state leakage |
|
||
no-get-with-default | disallow usage of the Ember's getWithDefault function |
|
|
|
no-get | require using ES5 getters instead of Ember's get / getProperties functions |
|
|
|
no-proxies | disallow using array or object proxies | |||
no-try-invoke | disallow usage of the Ember's tryInvoke util |
|
||
require-super-in-lifecycle-hooks | require super to be called in lifecycle hooks |
|
|
|
use-ember-get-and-set | enforce usage of Ember.get and Ember.set |
|
Name | Description |
|
|
|
---|---|---|---|---|
classic-decorator-hooks | enforce using correct hooks for both classic and non-classic classes |
|
||
classic-decorator-no-classic-methods | disallow usage of classic APIs such as get /set in classes that aren't explicitly decorated with @classic |
|
||
no-actions-hash | disallow the actions hash in components, controllers, and routes |
|
||
no-classic-classes | disallow "classic" classes in favor of native JS classes |
|
||
no-ember-super-in-es-classes | disallow use of this._super in ES class methods |
|
|
|
no-empty-glimmer-component-classes | disallow empty backing classes for Glimmer components |
|
Name | Description |
|
|
|
---|---|---|---|---|
jquery-ember-run | disallow usage of jQuery without an Ember run loop |
|
||
no-global-jquery | disallow usage of global jQuery object |
|
||
no-jquery | disallow any usage of jQuery |
|
Name | Description |
|
|
|
---|---|---|---|---|
named-functions-in-promises | enforce usage of named functions in promises | |||
no-html-safe | disallow the use of htmlSafe |
|||
no-incorrect-calls-with-inline-anonymous-functions | disallow inline anonymous functions as arguments to debounce , once , and scheduleOnce |
|
||
no-invalid-debug-function-arguments | disallow usages of Ember's assert() / warn() / deprecate() functions that have the arguments passed in the wrong order. |
|
||
no-restricted-property-modifications | disallow modifying the specified properties |
|
||
require-fetch-import | enforce explicit import for fetch() |
Name | Description |
|
|
|
---|---|---|---|---|
no-capital-letters-in-routes | disallow routes with uppercased letters in router.js |
|
||
no-controller-access-in-routes | disallow routes from accessing the controller outside of setupController/resetController |
|
||
no-private-routing-service | disallow injecting the private routing service |
|
||
no-shadow-route-definition | enforce no route path definition shadowing |
|
||
no-unnecessary-index-route | disallow unnecessary index route definition |
|||
no-unnecessary-route-path-option | disallow unnecessary usage of the route path option |
|
|
|
route-path-style | enforce usage of kebab-case (instead of snake_case or camelCase) in route paths |
|
||
routes-segments-snake-case | enforce usage of snake_cased dynamic segments in routes |
|
Name | Description |
|
|
|
---|---|---|---|---|
no-implicit-service-injection-argument | disallow omitting the injected service name argument |
|
||
no-restricted-service-injections | disallow injecting certain services under certain paths | |||
no-unnecessary-service-injection-argument | disallow unnecessary argument when injecting services |
|
||
no-unused-services | disallow unused service injections (see rule doc for limitations) |
|
Name | Description |
|
|
|
---|---|---|---|---|
order-in-components | enforce proper order of properties in components |
|
||
order-in-controllers | enforce proper order of properties in controllers |
|
||
order-in-models | enforce proper order of properties in models |
|
||
order-in-routes | enforce proper order of properties in routes |
|
Name | Description |
|
|
|
---|---|---|---|---|
no-current-route-name | disallow usage of the currentRouteName() test helper |
|||
no-ember-testing-in-module-scope | disallow use of Ember.testing in module scope |
|
||
no-invalid-test-waiters | disallow incorrect usage of test waiter APIs |
|
||
no-legacy-test-waiters | disallow the use of the legacy test waiter APIs |
|
||
no-noop-setup-on-error-in-before | disallows using no-op setupOnerror in before or beforeEach |
|
|
|
no-pause-test | disallow usage of the pauseTest helper in tests |
|
||
no-replace-test-comments | disallow 'Replace this with your real tests' comments in test files | |||
no-restricted-resolver-tests | disallow the use of patterns that use the restricted resolver in tests |
|
||
no-settled-after-test-helper | disallow usage of await settled() right after test helper that calls it internally |
|
|
|
no-test-and-then | disallow usage of the andThen test wait helper |
|
||
no-test-import-export | disallow importing of "-test.js" in a test file and exporting from a test file |
|
||
no-test-module-for | disallow usage of moduleFor , moduleForComponent , etc |
|
||
no-test-support-import | disallow importing of "test-support" files in production code. |
|
||
no-test-this-render | disallow usage of the this.render in tests, recommending to use @ember/test-helpers' render instead. |
|
||
prefer-ember-test-helpers | enforce usage of @ember/test-helpers methods over native window methods |
|
||
require-valid-css-selector-in-test-helpers | disallow using invalid CSS selectors in test helpers |
|
|
For the simplified list of rules, go here.
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.
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)yarn update
to automatically update the README and other files (and re-run this if you change the rule name or description)yarn test
yarn lint
(yarn lint:js --fix
can fix many errors)Note that new rules should not immediately be added to the recommended configuration, as we only consider such breaking changes during major version updates.
See the LICENSE file for license rights and limitations (MIT).
简介 检查语法错误 检查语法风格 修正语法 安装 //项目内安装 npm i -D eslint //全局安装 npm i -g eslint 初始化配置 eslint --init 运行该命令将会在目录下生成一个.eslintrc(.js|.json|.yml)文件,该文件就是eslint规则的配置文件 实例 { "rules": { "semi": ["error
ESLint介绍 我们知道,当下采用工具去完成项目代码的校验工作是更加高效和合理的,在这里我们使用的就是ESLint。 他是目前最为主流的javascrit lint工具,专门用于监测javascript代码的质量。通过ESLint就可以很容易的去统一不同开发者的编码风格。例如缩进,换行,分号以及空格之类的使用。 不仅如此,ESLint还可以帮助我们找出代码当中一些不合理的地方,例如我们定义了一个
目录 1、配置 ESLint 1.1、指定解析器选项 1.2、指定解析器 1.3、指定处理器 1.4、指定环境 1.5、指定全局变量 1.6、配置插件 1.7、配置规则 1.7.1、注释配置规则 1.7.2、文件配置规则 1.8、内联注释禁用规则 - 一行、块、整个文件 1.8.1、文件配置禁用规则 - 指定一组文件 1.9、添加共享设置 1.10、使用配置文件 1.11、配置文件格式 1.12、
eslint eslint 默认没有规则,需要手动配置 .eslintrc.* 中添加规则。 // .eslintrc.js module.exports = {} root 默认情况下,ESLint 会在所有父级目录里寻找配置文件,一直到根目录。如果你想要你所有项目都遵循一个特定的约定时,这将会很有用,但有时候会导致意想不到的结果。为了将 ESLint 限制到一个特定的项目,在你项目根目录下的
1.EsLint规则 ESLint Rules 所有的规则默认都是禁用的。在配置文件中,使用 "extends": "eslint:recommended" 来启用推荐的规则,报告一些常见的问题,在下文中这些推荐的规则都带有一个✔️标记。 Possible Errors 下面的规则指出了你可能犯错误的地方。 comma-dangle: 要求或禁止末尾逗号 no-cond-assig
ESLint 配置 ESlint 被设计为完全可配置的,这意味着你可以关闭每一个规则而只运行基本语法验证,或混合和匹配 ESLint 默认绑定的规则和你的自定义规则,以让 ESLint 更适合你的项目。有两种主要的方式来配置 ESLint: Configuration Comments - 使用 JavaScript 注释把配置信息直接嵌入到一个代码源文件中。 Configuration File
ESLint最初是由Nicholas C. Zakas 于2013年6月创建的开源项目。它的目标是提供一个插件化的javascript代码检测工具。对比于jshint显著的特点就是支持插件拓展还有就是支持jsx语法(jshint并不支持jsx,react开发老报错也是很头疼ㄟ( ▔, ▔ )ㄏ )。 命令行 具体的可以参考这里 传送门 或者 eslint -h, 这里给出几个常用的。 安装 npm
ESLint是在ECMAScript/JavaScript代码中识别和报告模式匹配的工具,它的目标是保证代码的一致性和避免错误。它和JSLint、JSHint相似,除了少数例外: ESLint 使用 Espress 解析 Javascript ESLint 使用AST去分析代码中的模式 完全插件化。每一个规则都是一个插件并且可以在运行时添加更多的规则。 1、命令行 安装 npm i -g esli
eslint-plugin-sql SQL linting rules for ESLint. In its current form, the plugin has been designed and tested to work with Postgres codebase. eslint-plugin-sql Installation Configuration Settings place
eslint-plugin-vue Official ESLint plugin for Vue.js �� Documentation See the official website. ⚓ Versioning Policy This plugin is following Semantic Versioning and ESLint's Semantic Versioning Policy.
eslint-plugin-node Additional ESLint's rules for Node.js �� Install & Usage $ npm install --save-dev eslint eslint-plugin-node Requires Node.js >=8.10.0 Requires ESLint >=5.16.0 Note: It recommends a
eslint-plugin-wxml 为 lint 微信小程序 wxml 文件而开发的 eslint 插件,可使用 eslint 来检查微信小程序项目内的 wxml 代码 当开发者使用 VSCode 或者 Webstorm 时可以得到代码错误提示,目前支持的 lint 规则如下: 1. wxml/colon-style-event-binding 强制使用:冒号隔开时间绑定 2. wxml/emp
Ember Best Practices This package has been deprecated: Please use eslint-plugin-ember. Deprecation details: Rule ID Status no-attrs-snapshot Deprecated in Octane no-attrs Deprecated in Octane no-broke
eslint-plugin-optimize-regex Optimize regex literals Installation You'll first need to install ESLint: npm i eslint --save-dev Next, install eslint-plugin-optimize-regex: npm install eslint-plugin-opt