@hs-web-team/eslint-config-node 1.0.0 → 2.1.0
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/.github/workflows/main.yml +4 -4
- package/.github/workflows/pr.yml +4 -4
- package/.github/workflows/release.yml +4 -4
- package/.nvmrc +1 -0
- package/.prettierrc.json +19 -0
- package/README.md +21 -0
- package/bin/add-prettier-scripts.js +62 -0
- package/index.js +12 -9
- package/package.json +7 -3
|
@@ -2,7 +2,7 @@ name: Merge to Main
|
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
push:
|
|
5
|
-
branches: [
|
|
5
|
+
branches: [main]
|
|
6
6
|
workflow_dispatch:
|
|
7
7
|
|
|
8
8
|
jobs:
|
|
@@ -11,13 +11,13 @@ jobs:
|
|
|
11
11
|
runs-on: ubuntu-latest
|
|
12
12
|
strategy:
|
|
13
13
|
matrix:
|
|
14
|
-
node: [
|
|
14
|
+
node: [20, 22]
|
|
15
15
|
|
|
16
16
|
name: Node ${{ matrix.node }} sample
|
|
17
17
|
steps:
|
|
18
|
-
- uses: actions/checkout@
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
19
|
- name: Run unit tests
|
|
20
|
-
uses: actions/setup-node@
|
|
20
|
+
uses: actions/setup-node@v4
|
|
21
21
|
with:
|
|
22
22
|
node-version: ${{ matrix.node }}
|
|
23
23
|
- run: npm install
|
package/.github/workflows/pr.yml
CHANGED
|
@@ -2,7 +2,7 @@ name: Pull Request
|
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
pull_request:
|
|
5
|
-
branches: [
|
|
5
|
+
branches: [main]
|
|
6
6
|
workflow_dispatch:
|
|
7
7
|
|
|
8
8
|
jobs:
|
|
@@ -11,13 +11,13 @@ jobs:
|
|
|
11
11
|
runs-on: ubuntu-latest
|
|
12
12
|
strategy:
|
|
13
13
|
matrix:
|
|
14
|
-
node: [
|
|
14
|
+
node: [20, 22]
|
|
15
15
|
|
|
16
16
|
name: Node ${{ matrix.node }} sample
|
|
17
17
|
steps:
|
|
18
|
-
- uses: actions/checkout@
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
19
|
- name: Run unit tests
|
|
20
|
-
uses: actions/setup-node@
|
|
20
|
+
uses: actions/setup-node@v4
|
|
21
21
|
with:
|
|
22
22
|
node-version: ${{ matrix.node }}
|
|
23
23
|
- run: npm install
|
|
@@ -7,12 +7,12 @@ jobs:
|
|
|
7
7
|
runs-on: ubuntu-latest
|
|
8
8
|
steps:
|
|
9
9
|
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
|
10
|
-
- uses: actions/checkout@
|
|
11
|
-
- uses: actions/setup-node@
|
|
10
|
+
- uses: actions/checkout@v4
|
|
11
|
+
- uses: actions/setup-node@v4
|
|
12
12
|
with:
|
|
13
|
-
node-version:
|
|
13
|
+
node-version: 22
|
|
14
14
|
registry-url: 'https://registry.npmjs.org'
|
|
15
15
|
- run: npm install
|
|
16
16
|
- run: npm publish
|
|
17
17
|
env:
|
|
18
|
-
NODE_AUTH_TOKEN:
|
|
18
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v22
|
package/.prettierrc.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"semi": true,
|
|
3
|
+
"singleQuote": true,
|
|
4
|
+
"tabWidth": 2,
|
|
5
|
+
"trailingComma": "all",
|
|
6
|
+
"printWidth": 120,
|
|
7
|
+
"bracketSpacing": true,
|
|
8
|
+
"arrowParens": "avoid",
|
|
9
|
+
"endOfLine": "lf",
|
|
10
|
+
"singleAttributePerLine": true,
|
|
11
|
+
"overrides": [
|
|
12
|
+
{
|
|
13
|
+
"files": ["*.yml", "*.yaml"],
|
|
14
|
+
"options": {
|
|
15
|
+
"singleQuote": false
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ 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
|
|
@@ -40,3 +41,23 @@ npm i -D @hs-web-team/eslint-config-node
|
|
|
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
|
+
```shell
|
|
52
|
+
npx @hs-web-team/eslint-config-node/bin/add-prettier-scripts.js
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
2. The script will:
|
|
56
|
+
- Add `prettier:check` and `prettier:write` scripts to your package.json
|
|
57
|
+
- Install Prettier as a dev dependency if not already installed
|
|
58
|
+
- Create a `.prettierrc.js` file with shared config
|
|
59
|
+
- Create a `.prettierignore` file with sensible defaults
|
|
60
|
+
|
|
61
|
+
3. After installation, you can use the following commands:
|
|
62
|
+
- `npm run prettier:check` - Check files for formatting issues
|
|
63
|
+
- `npm run prettier:write` - Automatically fix formatting issues
|
|
@@ -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();
|
package/index.js
CHANGED
|
@@ -4,20 +4,18 @@ module.exports = {
|
|
|
4
4
|
es2021: true,
|
|
5
5
|
node: true,
|
|
6
6
|
},
|
|
7
|
-
ignorePatterns: [
|
|
8
|
-
'/node_modules/',
|
|
9
|
-
'/.serverless/',
|
|
10
|
-
'/.eslintrc.js',
|
|
11
|
-
'/.webpack/',
|
|
12
|
-
],
|
|
7
|
+
ignorePatterns: ['/node_modules/', '/.serverless/', '/.eslintrc.js', '/.webpack/'],
|
|
13
8
|
extends: ['airbnb-base'],
|
|
14
9
|
parserOptions: {
|
|
15
10
|
ecmaVersion: 'latest',
|
|
16
11
|
},
|
|
17
12
|
rules: {
|
|
18
|
-
'no-console': [
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
'no-console': [
|
|
14
|
+
'error',
|
|
15
|
+
{
|
|
16
|
+
allow: ['info', 'warn', 'error'],
|
|
17
|
+
},
|
|
18
|
+
],
|
|
21
19
|
camelcase: 0,
|
|
22
20
|
'comma-dangle': 1,
|
|
23
21
|
'arrow-parens': 0,
|
|
@@ -38,5 +36,10 @@ module.exports = {
|
|
|
38
36
|
],
|
|
39
37
|
'operator-linebreak': 0,
|
|
40
38
|
'implicit-arrow-linebreaks': 0,
|
|
39
|
+
'implicit-arrow-linebreak': 0,
|
|
40
|
+
'object-curly-newline': 0,
|
|
41
|
+
'newline-per-chained-call': 0,
|
|
42
|
+
indent: 0,
|
|
43
|
+
'function-paren-newline': 0,
|
|
41
44
|
},
|
|
42
45
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hs-web-team/eslint-config-node",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "HubSpot Marketing WebTeam ESLint rules for Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
9
|
},
|
|
10
10
|
"engines": {
|
|
11
|
-
"node": ">=
|
|
11
|
+
"node": ">=22"
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"add-prettier": "./bin/add-prettier-scripts.js"
|
|
12
15
|
},
|
|
13
16
|
"repository": {
|
|
14
17
|
"type": "git",
|
|
@@ -26,6 +29,7 @@
|
|
|
26
29
|
"dependencies": {
|
|
27
30
|
"eslint": "^8.55.0",
|
|
28
31
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
29
|
-
"eslint-plugin-import": "^2.29.0"
|
|
32
|
+
"eslint-plugin-import": "^2.29.0",
|
|
33
|
+
"prettier": "^3.5.3"
|
|
30
34
|
}
|
|
31
35
|
}
|