ESLint
AppCode integrates with ESLint which brings a wide range of linting rules that can also be extended with plugins. AppCode shows warnings and errors reported by ESLint right in the editor, as you type. With ESLint, you can also use JavaScript Standard Style.
To view the description of a problem, hover over the highlighted code.
Installing, enabling, and configuring ESLint in AppCode
Open the built-in AppCode Terminal (⌥F12) and type
npm install eslint --save-dev
ornpm install eslint -g
at the command prompt.Optionally, install additional plugins, for example, eslint-plugin-react to lint React applications.
In the Settings/Preferences dialog (⌘,), choose JavaScript under Languages and Frameworks and then choose ESLint under Code Quality Tools. On the ESLint page page that opens, select the Enable checkbox. After that the controls on the page become available.
In the Node Interpreter field, specify the path to Node.js. If you followed the standard installation procedure, AppCode detects the path and fills in the field itself.
In the ESLint Package field, specify the location of the
eslint
orstandard
package.- Choose the configuration to use.
With Automatic search, AppCode looks for a
.eslintrc
file or tries to detect a configuration defined undereslintConfig
in apackage.json
. AppCode first looks for a.eslintrc
orpackage.json
in the folder with the file to be linted, then in its parent folder, and so on up to the project root.Choose Configuration File to use a custom file and specify the file location in the Path field.
- Optionally:
In the Extra ESLint Options field, specify additional command line options to run ESLint with, use spaces as separators.
In the Additional Rules Directory field, specify the location of the files with additional code verification rules. These rules will be applied after the rules from .eslintrc or the above specified custom configuration file and accordingly will override them.
Configuring highlighting for ESLint
By default, AppCode marks the detected errors and warnings based on the severity levels from the ESLint configuration. For example, errors are highlighted with a red squiggly line, while warnings are marked with a yellow background.
To change the severity level of a rule in the ESLint configuration
In .eslintrc or under
eslintConfig
in package.json, locate the rule you want to edit and set its ID to1
(warn
) or to2
(error
). Learn more from the ESLint official website.
You can override the severities from the ESLint configuration so that AppCode ignores them and shows everything reported by the linter as errors, warnings, or in a custom color.
To ignore the severity levels from the configuration
-
In the Settings/Preferences dialog (⌘,), select . The Inspections page opens.
-
In the central pane, go to JavaScript | Code quality tools | ESLint.
-
In the right-hand pane, clear the Use rule severity from the configuration file checkbox and select the severity level to use instead of the default one.
Importing code style from ESLint
You can import some of the ESLint code style rules to the AppCode JavaScript code style settings. That enables AppCode to use more accurate code style options for your project when auto-completing, generating, or refactoring the code or adding import statements. When you use the Reformat action, AppCode will then no longer break properly formatted code from the ESLint perspective.
AppCode understands ESLint configurations in all official formats: .eslintrc JSON files, package.json files with the eslintConfig
field, as well as JavaScript and YAML configuration files.
When you open your project for the first time, AppCode imports the code style from the project ESLint configuration automatically.
If your ESLint configuration is updated (manually or from your version control), open it in the editor and choose Apply ESLint Code Style Rules on the context menu: Alternatively, just answer Yes to the "Apply code style from ESLint?" question on top of the file: The list of applied rules is shown in the Event log tool window:
Using JavaScript Standard Style
You can set JavaScript Standard Style as default JavaScript code style for your application so its main rules are applied when you type the code or reformat it. Since Standard is based on ESLint, you can also use Standard via the AppCode ESLint integration.
To install JavaScript Standard
Open the built-in AppCode Terminal (⌥F12) and type
npm install standard --save-dev
at the command prompt. Learn more from the JavaScript Standard Style official website.
To enable linting with Standard via ESLint
In the Settings/Preferences dialog (⌘,), choose JavaScript under Languages and Frameworks and then choose ESLint under Code Quality Tools.
On the ESLint page that opens, select the Enable checkbox, and specify the location of the
standard
package in the ESLint Package field.
To set the JavaScript Standard Style as default
In the Settings/Preferences dialog (⌘,), choose ).
On the Code Style. JavaScript page that opens, click Set from, and then choose Predefined Style | JavaScript Standard Style. The style will replace your current scheme.
Linting TypeScript code with ESLint
If you prefer ESLint for checking your TypeScript code, you can install babel-eslint
, typescript-eslint-parser
, or eslint-plugin-typescript
and view ESLint errors and warnings in TypeScript files right in the editor.
If you are already using these parsers or the plugin, but you do not want to check TypeScript code with ESLint, add *.ts
to the .eslintignore file.
To use babel-eslint
Open the embedded Terminal (⌥F12), and type:
npm install eslint babel-eslint --save-dev
In the .eslintrc configuration file or under
eslintConfig
in package.json, add"parser":"babel-eslint"
.
To use typescript-eslint-parser
Open the embedded Terminal (⌥F12), and type:
npm install typescript-eslint-parser --save-dev
In the .eslintrc configuration file or under
eslintConfig
in package.json, add"parser":"typescript-eslint-parser"
.
To use eslint-plugin-typescript
Open the embedded Terminal (⌥F12) and type:
npm install typescript-eslint-parser eslint-plugin-typescript --save-dev
In the .eslintrc configuration file or under
eslintConfig
in package.json, add"parser":"typescript-eslint-parser"
and"plugins":“eslint-plugin-typescript”
.