@hs-web-team/eslint-config-node 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc.json +9 -1
- package/README.md +43 -16
- package/bin/add-prettier-scripts.js +62 -0
- package/docs/MIGRATION-V2.md +24 -0
- package/package.json +6 -3
package/.prettierrc.json
CHANGED
|
@@ -7,5 +7,13 @@
|
|
|
7
7
|
"bracketSpacing": true,
|
|
8
8
|
"arrowParens": "avoid",
|
|
9
9
|
"endOfLine": "lf",
|
|
10
|
-
"singleAttributePerLine": true
|
|
10
|
+
"singleAttributePerLine": true,
|
|
11
|
+
"overrides": [
|
|
12
|
+
{
|
|
13
|
+
"files": ["*.yml", "*.yaml"],
|
|
14
|
+
"options": {
|
|
15
|
+
"singleQuote": false
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
]
|
|
11
19
|
}
|
package/README.md
CHANGED
|
@@ -8,35 +8,62 @@ This is a list of ESLint rules that are recommended for use with **Hubspot Marke
|
|
|
8
8
|
|
|
9
9
|
- [Setup](#setup)
|
|
10
10
|
- [Where to use it](#where-to-use-it)
|
|
11
|
+
- [Using the Prettier Scripts](#using-the-prettier-scripts)
|
|
11
12
|
<!-- index-end -->
|
|
12
13
|
|
|
13
14
|
## Setup
|
|
14
15
|
|
|
15
16
|
1. Install as dev dependency
|
|
16
17
|
|
|
17
|
-
```
|
|
18
|
-
npm i -D @hs-web-team/eslint-config-node
|
|
19
|
-
```
|
|
18
|
+
```sh
|
|
19
|
+
npm i -D @hs-web-team/eslint-config-node@latest
|
|
20
|
+
```
|
|
20
21
|
|
|
21
22
|
2. Add to `.eslintrc` in project root directory
|
|
22
23
|
|
|
23
|
-
```json
|
|
24
|
-
{
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
```
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"extends": "@hs-web-team/eslint-config-node"
|
|
27
|
+
}
|
|
28
|
+
```
|
|
28
29
|
|
|
29
30
|
3. Extend the eslint on a project basis by adding rules to `.eslintrc` e.g.
|
|
30
31
|
|
|
31
|
-
```
|
|
32
|
-
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
```
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"extends": "@hs-web-team/eslint-config-node",
|
|
35
|
+
"settings": {
|
|
36
|
+
"import/resolver": "webpack"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
39
40
|
|
|
40
41
|
## Where to use it
|
|
41
42
|
|
|
42
43
|
This package is intended to be used as a starting point for ESLint rules for Backend Node.js projects, and not for use in browser environments.
|
|
44
|
+
|
|
45
|
+
## Using the Prettier Scripts
|
|
46
|
+
|
|
47
|
+
This package includes a utility script to automatically add Prettier configuration to your project.
|
|
48
|
+
|
|
49
|
+
1. Run the script:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
node ./node_modules/@hs-web-team/eslint-config-node/bin/add-prettier-scripts.js
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
2. The script will:
|
|
56
|
+
|
|
57
|
+
- Add `prettier:check` and `prettier:write` scripts to your package.json
|
|
58
|
+
- Install Prettier as a dev dependency if not already installed
|
|
59
|
+
- Create a `.prettierrc.js` file with shared config
|
|
60
|
+
- Create a `.prettierignore` file with sensible defaults
|
|
61
|
+
|
|
62
|
+
3. After installation, you can use the following commands:
|
|
63
|
+
|
|
64
|
+
- `npm run prettier:check` - Check files for formatting issues
|
|
65
|
+
- `npm run prettier:write` - Automatically fix formatting issues
|
|
66
|
+
|
|
67
|
+
## Migration from v1 to v2
|
|
68
|
+
|
|
69
|
+
See [MIGRATION-V2.md](./docs/MIGRATION-V2.md)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const packageJson = require('../package.json');
|
|
6
|
+
|
|
7
|
+
const { name } = packageJson;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Adds Prettier scripts to the package.json file
|
|
11
|
+
*/
|
|
12
|
+
const addPrettierScripts = () => {
|
|
13
|
+
console.info('Adding Prettier scripts to package.json...');
|
|
14
|
+
|
|
15
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
16
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
17
|
+
console.error('Error: package.json not found in the current directory');
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
23
|
+
|
|
24
|
+
packageJson.scripts = {
|
|
25
|
+
...packageJson.scripts,
|
|
26
|
+
'prettier:check': 'prettier --check .',
|
|
27
|
+
'prettier:write': 'prettier --write .',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`);
|
|
31
|
+
|
|
32
|
+
const prettierConfigPath = path.join(process.cwd(), '.prettierrc.js');
|
|
33
|
+
if (!fs.existsSync(prettierConfigPath)) {
|
|
34
|
+
console.info('Creating .prettierrc.js file...');
|
|
35
|
+
const prettierConfig =
|
|
36
|
+
`const sharedConfig = require('${name}/.prettierrc.json');
|
|
37
|
+
|
|
38
|
+
module.exports = sharedConfig;`;
|
|
39
|
+
fs.writeFileSync(prettierConfigPath, prettierConfig);
|
|
40
|
+
}
|
|
41
|
+
const prettierIgnorePath = path.join(process.cwd(), '.prettierignore');
|
|
42
|
+
if (!fs.existsSync(prettierIgnorePath)) {
|
|
43
|
+
console.info('Creating .prettierignore file...');
|
|
44
|
+
const ignoreContent =
|
|
45
|
+
`npm-shrinkwrap.json
|
|
46
|
+
package-lock.json
|
|
47
|
+
.eslintrc
|
|
48
|
+
*.html`;
|
|
49
|
+
fs.writeFileSync(prettierIgnorePath, ignoreContent);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
console.info('✅ Successfully added Prettier scripts to package.json');
|
|
53
|
+
console.info('You can now run:');
|
|
54
|
+
console.info(' npm run prettier:check - to check files for formatting issues');
|
|
55
|
+
console.info(' npm run prettier:write - to automatically fix formatting issues');
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error('Error updating package.json:', error.message);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
addPrettierScripts();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Migration from v1 to v2
|
|
2
|
+
|
|
3
|
+
## Steps to migrate
|
|
4
|
+
|
|
5
|
+
> **Note**
|
|
6
|
+
>
|
|
7
|
+
> This migration requires a manual review of the changes and also that you run your project in Node.js v22 or higher.
|
|
8
|
+
|
|
9
|
+
- [ ] Upgrade to Node.js v22 or higher
|
|
10
|
+
- [ ] Upgrade all dependencies to the latest version
|
|
11
|
+
- [ ] Update the package `npm install @hs-web-team/eslint-config-node@latest`
|
|
12
|
+
- [ ] Run the script `node ./node_modules/@hs-web-team/eslint-config-node/bin/add-prettier-scripts.js`
|
|
13
|
+
- [ ] Commit the changes
|
|
14
|
+
- [ ] Run the `prettier:check` command to preview what it's being changed
|
|
15
|
+
- [ ] Adjust the `.prettierignore` according to your project requirements, as you may not want to format certain files
|
|
16
|
+
- [ ] Run the `prettier:write` command to format the files
|
|
17
|
+
- [ ] Hope for the best :-D
|
|
18
|
+
- [ ] Test locally that everything is working correctly
|
|
19
|
+
- [ ] Commit the changes
|
|
20
|
+
- [ ] Create a PR
|
|
21
|
+
- [ ] Get it approved
|
|
22
|
+
- [ ] Merge it into `main`
|
|
23
|
+
- [ ] Test everything in QA
|
|
24
|
+
- [ ] Celebrate! 🎉
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hs-web-team/eslint-config-node",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "HubSpot Marketing WebTeam ESLint rules for Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": ">=22"
|
|
12
12
|
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"add-prettier": "./bin/add-prettier-scripts.js"
|
|
15
|
+
},
|
|
13
16
|
"repository": {
|
|
14
17
|
"type": "git",
|
|
15
18
|
"url": "git+https://github.com/HubSpotWebTeam/wt-eslint-node.git"
|
|
@@ -24,9 +27,9 @@
|
|
|
24
27
|
},
|
|
25
28
|
"homepage": "https://github.com/HubSpotWebTeam/wt-eslint-node#readme",
|
|
26
29
|
"dependencies": {
|
|
27
|
-
"eslint": "^8.
|
|
30
|
+
"eslint": "^8.57.1",
|
|
28
31
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
29
|
-
"eslint-plugin-import": "^2.
|
|
32
|
+
"eslint-plugin-import": "^2.31.0",
|
|
30
33
|
"prettier": "^3.5.3"
|
|
31
34
|
}
|
|
32
35
|
}
|