You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ESLint core rules are the rules included in the ESLint package.
11
+
12
+
## Rule Writing Documentation
13
+
14
+
For full reference information on writing rules, refer to [Custom Rules](../extend/custom-rules). Both custom rules and core rules have the same API. The primary difference between core and custom rules are:
15
+
16
+
1. Core rules are included in the `eslint` package.
17
+
1. Core rules must adhere to the conventions documented on this page.
18
+
19
+
## File Structure
20
+
21
+
Each core rule in ESLint has three files named with its identifier (for example, `no-extra-semi`).
22
+
23
+
* in the `lib/rules` directory: a source file (for example, `no-extra-semi.js`)
24
+
* in the `tests/lib/rules` directory: a test file (for example, `no-extra-semi.js`)
25
+
* in the `docs/src/rules` directory: a Markdown documentation file (for example, `no-extra-semi.md`)
26
+
27
+
**Important:** If you submit a core rule to the ESLint repository, you **must** follow the conventions explained below.
28
+
29
+
Here is the basic format of the source file for a rule:
30
+
31
+
```js
32
+
/**
33
+
* @fileoverview Rule to disallow unnecessary semicolons
Each bundled rule for ESLint core must have a set of unit tests submitted with it to be accepted. The test file is named the same as the source file but lives in `tests/lib/`. For example, if the rule source file is `lib/rules/foo.js` then the test file should be `tests/lib/rules/foo.js`.
67
+
68
+
ESLint provides the [`RuleTester`](../integrate/nodejs-api#ruletester) utility to make it easy to write tests for rules.
69
+
70
+
## Performance Testing
71
+
72
+
To keep the linting process efficient and unobtrusive, it is useful to verify the performance impact of new rules or modifications to existing rules.
73
+
74
+
To learn how to profile the performance of individual rules, refer to [Profile Rule Performance](../extend/custom-rules#profile-rule-performance) in the custom rules documentation.
75
+
76
+
When developing in the ESLint core repository, the `npm run perf` command gives a high-level overview of ESLint running time with all core rules enabled.
Copy file name to clipboardExpand all lines: docs/src/contribute/index.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,6 +50,10 @@ Have some extra time and want to contribute? This section talks about the proces
50
50
51
51
We're always looking for contributions from the community. This section explains the requirements for pull requests and the process of contributing code.
52
52
53
+
## [Contribute to Core Rules](core-rules)
54
+
55
+
This section explains how to add to the core rules of ESLint.
56
+
53
57
## [Governance](governance)
54
58
55
59
Describes the governance policy for ESLint, including the rights and privileges of individuals inside the project.
@@ -712,47 +693,25 @@ You can access that code path objects with five events related to code paths.
712
693
713
694
## Rule Unit Tests
714
695
715
-
Each bundled rule for ESLint core must have a set of unit tests submitted with it to be accepted. The test file is named the same as the source file but lives in `tests/lib/`. For example, if the rule source file is `lib/rules/foo.js` then the test file should be `tests/lib/rules/foo.js`.
716
-
717
696
ESLint provides the [`RuleTester`](../integrate/nodejs-api#ruletester) utility to make it easy to write tests for rules.
718
697
719
-
## Performance Testing
698
+
## Rule Naming Conventions
720
699
721
-
To keep the linting process efficient and unobtrusive, it is useful to verify the performance impact of new rules or modifications to existing rules.
700
+
While you can give a custom rule any name you'd like, the core rules have naming conventions that it could be clearer to apply to your custom rule. To learn more, refer to the [Core Rule Naming Conventions](../contribute/core-rules#rule-naming-conventions) documentation.
722
701
723
-
### Overall Performance
702
+
##Runtime Rules
724
703
725
-
When developing in the ESLint core repository, the `npm run perf` command gives a high-level overview of ESLint running time with all core rules enabled.
704
+
The thing that makes ESLint different from other linters is the ability to define custom rules at runtime. This is perfect for rules that are specific to your project or company and wouldn't make sense for ESLint to ship with. With runtime rules, you don't have to wait for the next version of ESLint or be disappointed that your rule isn't general enough to apply to the larger JavaScript community, just write your rules and include them at runtime.
Runtime rules are written in the same format as all other rules. Create your rule as you would any other and then follow these steps:
707
+
708
+
1. Place all of your runtime rules in the same directory (e.g., `eslint_rules`).
709
+
2. Create a [configuration file](../use/configure/) and specify your rule ID error level under the `rules` key. Your rule will not run unless it has a value of `"warn"` or `"error"` in the configuration file.
710
+
3. Run the [command line interface](../use/command-line-interface) using the `--rulesdir` option to specify the location of your runtime rules.
752
711
753
-
### Per-rule Performance
712
+
##Profile Rule Performance
754
713
755
-
ESLint has a built-in method to track performance of individual rules. Setting the `TIMING` environment variable will trigger the display, upon linting completion, of the ten longest-running rules, along with their individual running time (rule creation + rule execution) and relative performance impact as a percentage of total rule processing time (rule creation + rule execution).
714
+
ESLint has a built-in method to track the performance of individual rules. Setting the `TIMING` environment variable will trigger the display, upon linting completion, of the ten longest-running rules, along with their individual running time (rule creation + rule execution) and relative performance impact as a percentage of total rule processing time (rule creation + rule execution).
756
715
757
716
```bash
758
717
$ TIMING=1 eslint lib
@@ -780,21 +739,3 @@ quotes | 18.066 | 100.0%
780
739
```
781
740
782
741
To see a longer list of results (more than 10), set the environment variable to another value such as `TIMING=50` or `TIMING=all`.
783
-
784
-
## Rule Naming Conventions
785
-
786
-
The rule naming conventions for ESLint are fairly simple:
787
-
788
-
* If your rule is disallowing something, prefix it with `no-` such as `no-eval` for disallowing `eval()` and `no-debugger` for disallowing `debugger`.
789
-
* If your rule is enforcing the inclusion of something, use a short name without a special prefix.
790
-
* Use dashes between words.
791
-
792
-
## Runtime Rules
793
-
794
-
The thing that makes ESLint different from other linters is the ability to define custom rules at runtime. This is perfect for rules that are specific to your project or company and wouldn't make sense for ESLint to ship with. With runtime rules, you don't have to wait for the next version of ESLint or be disappointed that your rule isn't general enough to apply to the larger JavaScript community, just write your rules and include them at runtime.
795
-
796
-
Runtime rules are written in the same format as all other rules. Create your rule as you would any other and then follow these steps:
797
-
798
-
1. Place all of your runtime rules in the same directory (e.g., `eslint_rules`).
799
-
2. Create a [configuration file](../use/configure/) and specify your rule ID error level under the `rules` key. Your rule will not run unless it has a value of `"warn"` or `"error"` in the configuration file.
800
-
3. Run the [command line interface](../use/command-line-interface) using the `--rulesdir` option to specify the location of your runtime rules.
0 commit comments