https://github.com/markablov/eslint-plugin-node-cjs-extension
ESLint plugin to check consistency in require() calls - with or without extensions.
https://github.com/markablov/eslint-plugin-node-cjs-extension
Last synced: over 1 year ago
JSON representation
ESLint plugin to check consistency in require() calls - with or without extensions.
- Host: GitHub
- URL: https://github.com/markablov/eslint-plugin-node-cjs-extension
- Owner: markablov
- License: unlicense
- Created: 2020-03-09T07:32:19.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T09:35:46.000Z (over 3 years ago)
- Last Synced: 2023-11-03T11:27:22.284Z (over 2 years ago)
- Language: JavaScript
- Size: 966 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# eslint-plugin-node-cjs-extension
Check consistency in require() usage - load CJS modules with or without extensions.
## Installation
You'll first need to install [ESLint](http://eslint.org):
```
$ npm i eslint --save-dev
```
Next, install `eslint-plugin-node-cjs-extension`:
```
$ npm install eslint-plugin-node-cjs-extension --save-dev
```
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-node-cjs-extension` globally.
## Usage
Add `node-cjs-extension` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
```json
{
"plugins": [
"node-cjs-extension"
]
}
```
## Rule
Main goal is to enforce the style of file extensions in `require()` declarations
### Options
```json
{
"rules": {
"node-cjs-extension/require-cjs-extension": ["error", "always" or "never"]
}
}
```
`always` - to force usage of file extensions (option is set to that by default)
Correct code:
```
/* eslint node-cjs-extension/require-cjs-extension: ["error", "always"] */
require("./path/to/a/file.js");
```
Incorrect code:
```
/* eslint node-cjs-extension/require-cjs-extension: ["error", "always"] */
require("./path/to/a/file");
```
`never` - to force skipping file extensions
```
/* eslint node-cjs-extension/require-cjs-extension: ["error", "never"] */
require("./path/to/a/file");
```
Incorrect code:
```
/* eslint node-cjs-extension/require-cjs-extension: ["error", "never"] */
require("./path/to/a/file.js");
```