|
10 | 10 |
|
11 | 11 | This package provides utility functions and classes for make ESLint custom rules. |
12 | 12 |
|
13 | | -For example, there is the class which tracks variable references. |
| 13 | +For examples: |
14 | 14 |
|
15 | | -```js |
16 | | -const { ReferenceTracker } = require("eslint-utils") |
17 | | - |
18 | | -module.exports = { |
19 | | - meta: {}, |
20 | | - create(context) { |
21 | | - return { |
22 | | - "Program:exit"() { |
23 | | - const tracker = new ReferenceTracker(context.getScope()) |
24 | | - |
25 | | - // Track the references of global variables. |
26 | | - for (const { node, path } of tracker.iterateGlobalReferences({ |
27 | | - // Iterate the call expressions of `console.log`, `console.info` |
28 | | - console: { |
29 | | - log: { [ReferenceTracker.CALL]: true }, |
30 | | - info: { [ReferenceTracker.CALL]: true }, |
31 | | - }, |
32 | | - })) { |
33 | | - context.report({ |
34 | | - node, |
35 | | - message: "Don't use {{name}}.", |
36 | | - data: { name: path.join(".") }, |
37 | | - }) |
38 | | - } |
39 | | - |
40 | | - // Track the references of CommonJS modules. |
41 | | - for (const { node, path } of tracker.iterateCjsReferences({ |
42 | | - // Iterate the access of `fs.exists`. |
43 | | - fs: { |
44 | | - exists: { [ReferenceTracker.READ]: true }, |
45 | | - }, |
46 | | - })) { |
47 | | - context.report({ |
48 | | - node, |
49 | | - message: "Don't use {{name}}.", |
50 | | - data: { name: path.join(".") }, |
51 | | - }) |
52 | | - } |
53 | | - } |
54 | | - } |
55 | | - }, |
56 | | -} |
57 | | -``` |
58 | | - |
59 | | -## 💿 Installation |
60 | | - |
61 | | -Use [npm](https://www.npmjs.com/) or [yarn](https://yarnpkg.com/). |
62 | | - |
63 | | -``` |
64 | | -npm install eslint-utils |
65 | | -``` |
66 | | - |
67 | | -### Requirements |
68 | | - |
69 | | -- Node.js `6.5.0` or newer. |
| 15 | +- [getStaticValue](https://mysticatea.github.io/eslint-utils/api/ast-utils.html#getstaticvalue) evaluates static value on AST. |
| 16 | +- [PatternMatcher](https://mysticatea.github.io/eslint-utils/api/ast-utils.html#patternmatcher-class) finds a regular expression pattern as handling escape sequences. |
| 17 | +- [ReferenceTracker](https://mysticatea.github.io/eslint-utils/api/scope-utils.html#referencetracker-class) checks the members of modules/globals as handling assignments and destructuring. |
70 | 18 |
|
71 | 19 | ## 📖 Usage |
72 | 20 |
|
73 | | -See [API reference](https://mysticatea.github.io/eslint-utils/). |
| 21 | +See [documentation](https://mysticatea.github.io/eslint-utils/). |
74 | 22 |
|
75 | 23 | ## 📰 Changelog |
76 | 24 |
|
|
0 commit comments