Custom ProcessorsĪn ESLint processor extracts JavaScript code from other kinds of files, then lets ESLint lint the JavaScript code. Often custom parsers are included as part of shareable configurations or plugins, so you don’t have to use them directly.įor example, is a custom parser included in the typescript-eslint project that lets ESLint parse TypeScript code. By default, ESLint uses the built-in Espree parser, which is compatible with standard JavaScript runtimes and versions.Ĭustom parsers let ESLint parse non-standard JavaScript syntax. ParsersĪn ESLint parser converts code into an abstract syntax tree that ESLint can evaluate. For example, contains best practices for using the Angular framework.įor more information, refer to Configure Plugins. Plugins can be used to enforce a style guide and support JavaScript extensions (like TypeScript), libraries (like React), and frameworks (Angular).Ī popular use case for plugins is to enforce best practices for a framework. PluginsĪn ESLint plugin is an npm module that can contain a set of ESLint rules, configurations, processors, and environments. For example the sharable configuration eslint-config-airbnb-base implements the popular Airbnb JavaScript style guide.įor more information, refer to Using a shareable configuration package. Often shareable configurations are used to enforce style guides using ESLint’s built-in rules. Shareable configurations are ESLint configurations that are shared via npm. You can include built-in rules, how you want them enforced, plugins with custom rules, shareable configurations, which files you want rules to apply to, and more.įor more information, refer to Configuration Files. Configuration FilesĪn ESLint configuration file is a place where you put the configuration for ESLint in your project. You can also create custom rules or use rules that others have created with plugins.įor more information, refer to Rules. You can set the rule to either always require semicolons or require that a statement never ends with a semicolon.ĮSLint contains hundreds of built-in rules that you can use. Rules can also contain additional configuration options specific to that rule.įor example, the semi rule lets you specify whether or not JavaScript statements should end with a semicolon ( ). A rule validates if your code meets a certain expectation, and what to do if it does not meet that expectation. Rules are the core building block of ESLint. Problems can be anything from potential runtime bugs, to not following best practices, to styling issues. It helps you find and fix problems in your JavaScript code. What is ESLint?ĮSLint is a configurable JavaScript linter. These rules will become more complicated as new features become a part of JavaScript.This page contains a high-level overview of some of the core concepts of ESLint. ASI contains a few eccentric behaviors, though, and your code will break if JavaScript misinterprets your line break. Why? When JavaScript encounters a line break without a semicolon, it uses a set of rules called Automatic Semicolon Insertion to determine whether it should regard that line break as the end of a statement, and (as the name implies) place a semicolon into your code before the line break if it thinks so. See Translationġ.1 Primitives: When you access a primitive type you work directly on its value.Ĭonst numbers = // bad let sum = 0 for ( let num of numbers ) // bad createHero ( firstName, lastName, inventorOf ) // good createHero ( firstName, lastName, inventorOf, ) // good (note that a comma must not appear after a "rest" element) createHero ( firstName, lastName, inventorOf , This guide is available in other languages too. It also assumes you are installing shims/polyfills in your app, with airbnb-browser-shims or the equivalent. Note: this guide assumes you are using Babel, and requires that you use babel-preset-airbnb or the equivalent. A mostly reasonable approach to JavaScript
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |