Skip to content

Commit af4b5c0

Browse files
committed
Stop using mjs file extension
1 parent 08e1c8c commit af4b5c0

File tree

7 files changed

+41
-17
lines changed

7 files changed

+41
-17
lines changed
File renamed without changes.

specification/package-lock.json

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

validator/README.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
11
# es-spec-validator
22

33
An [ESLint](https://eslint.org/) plugin that uses [typescript-eslint](https://typescript-eslint.io/) to validate the Elasticsearch specification against a set of custom rules.
4-
It is configured [in the specification directory](../specification/eslint.config.mjs).
4+
It is configured [in the specification directory](../specification/eslint.config.js).
55

66
## Rules
77

88
| Name | Description |
99
| - | - |
1010
| `single-key-dictionary-key-is-string` | `SingleKeyDictionary` keys must be strings |
1111

12-
## Writing rules
12+
## Usage
1313

14-
Each rule should be written in a separate JavaScript file (e.g. `single-key-dictionary-key-is-string.mjs`) following the format of a custom rule [as defined by the typescript-eslint docs](https://typescript-eslint.io/developers/custom-rules).
15-
Within a rule's `create` function, return an object whose keys are the names of [AST node types](https://typescript-eslint.io/packages/typescript-estree/ast-spec).
14+
Prerequisites: [Node.js](https://nodejs.org) and [`npm`](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) must be installed locally.
1615

17-
If a rule needs to report a problem, it should call `context.report()` with the appropriate arguments.
16+
1. Enter the `specification/` directory: `cd specification/`
17+
1. Install dependencies (first time only): `npm install`
18+
1. Run the linter on the specification project: `npm run lint`
19+
20+
Or, from the repository's root directory, run `make setup && make validate`.
21+
This will run the linter, along with several other validations.
22+
23+
If the linter finds problems in the spec code, it will print them out.
24+
If all is well, the output will be minimal, and the process will exit cleanly.
25+
26+
ESLint also maintains [integrations](https://eslint.org/docs/latest/use/integrations#editors) for most common code editors to provide instant inline feedback as you modify files.
27+
28+
## Writing new linter rules
29+
30+
Each rule should be written in a separate JavaScript file (e.g. `single-key-dictionary-key-is-string.js`) following the format of a custom rule [as defined by the typescript-eslint docs](https://typescript-eslint.io/developers/custom-rules).
31+
Within a rule's `create` function, return an object whose keys are the names of [AST node types](https://typescript-eslint.io/packages/typescript-estree/ast-spec) and whose values are functions that validate that node type.
32+
To report a problem in a validation function, it should call `context.report()` with the appropriate arguments.
1833

1934
To get a familiar the different node types possible within a TypeScript AST, paste some code into [an AST viewer](https://ts-ast-viewer.com/) and explore the resulting visual tree.
2035

21-
To add your rule to the spec validator ESLint plugin, import it into [the plugin file](./eslint-plugin-es-spec.mjs) and add it to the `rules` object with an appropriate key.
36+
To add your rule to the spec validator ESLint plugin, import it into [the plugin file](./eslint-plugin-es-spec.js) and add it to the `rules` object with an appropriate key.
37+
38+
### ESM format
39+
40+
The validator project is written in standard JavaScript rather than TypeScript, and uses the new [ESM](https://nodejs.org/api/esm.html) module format for managing module imports and exports.
41+
Files should use the normal `.js` file extension, and the `import` format is almost identical to TypeScript's, except that ESM requires you to include the file extension in the import statement. Example:
42+
43+
```js
44+
import myRule from './rules/my-rule.js' // not ./rules/my-rule
45+
```

validator/eslint-plugin-es-spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import singleKeyDict from './rules/single-key-dictionary-key-is-string.js'
2+
3+
export default {
4+
rules: {
5+
'single-key-dictionary-key-is-string': singleKeyDict
6+
}
7+
}

validator/eslint-plugin-es-spec.mjs

Lines changed: 0 additions & 7 deletions
This file was deleted.

validator/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "eslint-plugin-es-spec",
33
"version": "0.1.0",
44
"description": "Elasticsearch specification validation",
5-
"main": "eslint-plugin-es-spec.mjs",
5+
"main": "eslint-plugin-es-spec.js",
6+
"type": "module",
67
"scripts": {
78
"test": "echo \"Error: no test specified\" && exit 1"
89
},

0 commit comments

Comments
 (0)