@hs-web-team/eslint-config-node 2.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/.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,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hs-web-team/eslint-config-node",
3
- "version": "2.0.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": {
@@ -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"