@geprom/eslint-prettier-sapient 1.0.2 → 1.0.5

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 GEPROM
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GEPROM
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,116 +1,78 @@
1
- # @geprom/eslint-prettier-sapient
2
-
3
- ESLint and Prettier configuration for Geprom Sapient projects with support for both camelCase and snake_case naming conventions.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm i @geprom/eslint-prettier-sapient
9
- ```
10
-
11
- ## Usage
12
-
13
- Create an `.eslintrc.js` file in your project root:
14
-
15
- ```javascript
16
- module.exports = {
17
- extends: ['@geprom/eslint-prettier-sapient'],
18
- };
19
- ```
20
-
21
- Create a `.prettierrc.js` file in your project root:
22
-
23
- ```javascript
24
- module.exports = {
25
- printWidth: 100,
26
- singleQuote: true,
27
- trailingComma: 'es5',
28
- bracketSpacing: true,
29
- semi: true,
30
- useTabs: false,
31
- tabWidth: 2,
32
- arrowParens: 'always',
33
- };
34
- ```
35
-
36
- Add scripts to your `package.json`:
37
-
38
- ```json
39
- {
40
- "scripts": {
41
- "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
42
- "lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
43
- "format": "prettier --write .",
44
- "format:check": "prettier --check ."
45
- }
46
- }
47
- ```
48
-
49
- ## Features
50
-
51
- - Airbnb ESLint ruleset
52
- - Prettier integration
53
- - Both camelCase and snake_case naming support
54
- - ✅ Preconfigured globals: `DbCon`, `DbQuery`, `logger`
55
-
56
- ## Configuration Details
57
-
58
- ### Supported Naming Conventions
59
-
60
- Both naming styles are accepted without warnings:
61
-
62
- - `someFunction` (camelCase)
63
- - `some_function` (snake_case)
64
-
65
- ### Application Globals
66
-
67
- These globals are pre-declared and don't require imports, any additional global variable available in Sapient should :
68
-
69
- - `DbCon` - Database connection class
70
- - `DbQuery` - Database query class
71
- - `logger` - Logger instance
72
-
73
- To extend with additional globals:
74
-
75
- ```javascript
76
- module.exports = {
77
- extends: ['@geprom/eslint-prettier-sapient'],
78
- globals: {
79
- myCustomGlobal: 'readonly',
80
- },
81
- };
82
- ```
83
-
84
- ### ESLint Rules
85
-
86
- - **camelcase**: Flexible naming - accepts both camelCase and snake_case patterns
87
- - **jsx-a11y/href-no-hash**: Disabled
88
- - **react/jsx-filename-extension**: Warns for .js files (allows .jsx)
89
- - **max-len**: 100 character limit with exceptions for comments, URLs, and strings
90
- - **react/prop-types**: Warning level
91
- - **no-unused-vars**: Ignores variables starting with underscore
92
-
93
- ### Prettier Options
94
-
95
- - **printWidth**: 100 characters
96
- - **singleQuote**: true
97
- - **trailingComma**: 'es5'
98
- - **bracketSpacing**: true
99
- - **semi**: true
100
- - **useTabs**: false
101
- - **tabWidth**: 2 spaces
102
- - **arrowParens**: 'always'
103
-
104
- ## Extending the Configuration
105
-
106
- You can extend or override rules in your project's `.eslintrc.js`:
107
-
108
- ```javascript
109
- module.exports = {
110
- extends: ['@geprom/eslint-prettier-sapient'],
111
- rules: {
112
- 'max-len': ['warn', { code: 120 }], // Override max line length
113
- 'no-console': 'warn', // Add custom rule
114
- },
115
- };
116
- ```
1
+ # @geprom/eslint-prettier-sapient
2
+
3
+ ESLint and Prettier configuration for Geprom Sapient projects with support for both camelCase and snake_case naming conventions.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i @geprom/eslint-prettier-sapient
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - Airbnb ESLint ruleset
14
+ - ✅ Prettier integration
15
+ - ✅ Both camelCase and snake_case naming support
16
+ - Preconfigured globals: `DbCon`, `DbQuery`, `logger`
17
+
18
+ ## Configuration Details
19
+
20
+ ### Supported Naming Conventions
21
+
22
+ Both naming styles are accepted without warnings:
23
+
24
+ - `someFunction` (camelCase)
25
+ - `some_function` (snake_case)
26
+
27
+ ### Application Globals
28
+
29
+ These globals are pre-declared and don't require imports, any additional global variable available in Sapient should :
30
+
31
+ - `DbCon` - Database connection class
32
+ - `DbQuery` - Database query class
33
+ - `logger` - Logger instance
34
+
35
+ To extend with additional globals:
36
+
37
+ ```javascript
38
+ module.exports = {
39
+ extends: ['@geprom/eslint-prettier-sapient'],
40
+ globals: {
41
+ myCustomGlobal: 'readonly',
42
+ },
43
+ };
44
+ ```
45
+
46
+ ### ESLint Rules
47
+
48
+ - **camelcase**: Flexible naming - accepts both camelCase and snake_case patterns
49
+ - **jsx-a11y/href-no-hash**: Disabled
50
+ - **react/jsx-filename-extension**: Warns for .js files (allows .jsx)
51
+ - **max-len**: 100 character limit with exceptions for comments, URLs, and strings
52
+ - **react/prop-types**: Warning level
53
+ - **no-unused-vars**: Ignores variables starting with underscore
54
+
55
+ ### Prettier Options
56
+
57
+ - **printWidth**: 100 characters
58
+ - **singleQuote**: true
59
+ - **trailingComma**: 'es5'
60
+ - **bracketSpacing**: true
61
+ - **semi**: true
62
+ - **useTabs**: false
63
+ - **tabWidth**: 2 spaces
64
+ - **arrowParens**: 'always'
65
+
66
+ ## Extending the Configuration
67
+
68
+ You can extend or override rules in your project's `.eslintrc.js`:
69
+
70
+ ```javascript
71
+ module.exports = {
72
+ extends: ['@geprom/eslint-prettier-sapient'],
73
+ rules: {
74
+ 'max-len': ['warn', { code: 120 }], // Override max line length
75
+ 'no-console': 'warn', // Add custom rule
76
+ },
77
+ };
78
+ ```
package/index.js CHANGED
@@ -1,66 +1,67 @@
1
- module.exports = {
2
- extends: ["airbnb", "plugin:prettier/recommended", "prettier"],
3
- env: {
4
- browser: true,
5
- commonjs: true,
6
- es6: true,
7
- jest: true,
8
- node: true,
9
- },
10
- parser: "espree",
11
- parserOptions: {
12
- ecmaVersion: 2020,
13
- sourceType: "module",
14
- ecmaFeatures: {
15
- jsx: true,
16
- },
17
- },
18
- globals: {
19
- DbCon: "readonly",
20
- DbQuery: "readonly",
21
- logger: "readonly",
22
- },
23
- rules: {
24
- camelcase: [
25
- "warn",
26
- {
27
- properties: "never",
28
- ignoreDestructuring: true,
29
- allow: ["^[a-z]+(_[a-z]+)*$", "^[a-zA-Z]+([A-Z][a-z]+)*$"],
30
- },
31
- ],
32
- "jsx-a11y/href-no-hash": ["off"],
33
- "react/jsx-filename-extension": [
34
- "warn",
35
- {
36
- extensions: [".js", ".jsx"],
37
- },
38
- ],
39
- "max-len": [
40
- "warn",
41
- {
42
- code: 100,
43
- tabWidth: 2,
44
- comments: 100,
45
- ignoreComments: false,
46
- ignoreTrailingComments: true,
47
- ignoreUrls: true,
48
- ignoreStrings: true,
49
- ignoreTemplateLiterals: true,
50
- ignoreRegExpLiterals: true,
51
- },
52
- ],
53
- "react/prop-types": [1],
54
- "no-unused-vars": [
55
- "warn",
56
- {
57
- argsIgnorePattern: "^_",
58
- },
59
- ],
60
- },
61
- settings: {
62
- react: {
63
- version: "detect",
64
- },
65
- },
66
- };
1
+ module.exports = {
2
+ extends: ["airbnb", "plugin:prettier/recommended", "prettier"],
3
+ env: {
4
+ browser: true,
5
+ commonjs: true,
6
+ es6: true,
7
+ jest: true,
8
+ node: true,
9
+ },
10
+ parser: "espree",
11
+ parserOptions: {
12
+ ecmaVersion: 2020,
13
+ sourceType: "module",
14
+ ecmaFeatures: {
15
+ jsx: true,
16
+ },
17
+ },
18
+ globals: {
19
+ DbCon: "readonly",
20
+ DbQuery: "readonly",
21
+ execute: "readonly",
22
+ logger: "readonly",
23
+ },
24
+ rules: {
25
+ camelcase: [
26
+ "warn",
27
+ {
28
+ properties: "never",
29
+ ignoreDestructuring: true,
30
+ allow: ["^[a-z]+(_[a-z]+)*$", "^[a-zA-Z]+([A-Z][a-z]+)*$", "^[a-z]+(_([a-z]+|[A-Z]+))*$"],
31
+ },
32
+ ],
33
+ "jsx-a11y/href-no-hash": ["off"],
34
+ "react/jsx-filename-extension": [
35
+ "warn",
36
+ {
37
+ extensions: [".js", ".jsx"],
38
+ },
39
+ ],
40
+ "max-len": [
41
+ "warn",
42
+ {
43
+ code: 100,
44
+ tabWidth: 2,
45
+ comments: 100,
46
+ ignoreComments: false,
47
+ ignoreTrailingComments: true,
48
+ ignoreUrls: true,
49
+ ignoreStrings: true,
50
+ ignoreTemplateLiterals: true,
51
+ ignoreRegExpLiterals: true,
52
+ },
53
+ ],
54
+ "react/prop-types": [1],
55
+ "no-unused-vars": [
56
+ "warn",
57
+ {
58
+ argsIgnorePattern: "^_",
59
+ },
60
+ ],
61
+ },
62
+ settings: {
63
+ react: {
64
+ version: "detect",
65
+ },
66
+ },
67
+ };
package/package.json CHANGED
@@ -1,47 +1,53 @@
1
- {
2
- "name": "@geprom/eslint-prettier-sapient",
3
- "version": "1.0.2",
4
- "description": "ESLint and Prettier configuration for Geprom Sapient projects with snake_case and camelCase support",
5
- "main": "index.js",
6
- "scripts": {
7
- "postinstall": "node setup.js"
8
- },
9
- "files": [
10
- "index.js",
11
- "setup.js",
12
- "prettier-config.js"
13
- ],
14
- "keywords": [
15
- "eslint",
16
- "eslintconfig",
17
- "prettier",
18
- "airbnb",
19
- "react",
20
- "code-style",
21
- "linter"
22
- ],
23
- "author": "GEPROM",
24
- "license": "MIT",
25
- "peerDependencies": {
26
- "eslint": "^8.0.0",
27
- "prettier": "^2.8.0"
28
- },
29
- "devDependencies": {
30
- "eslint": "^8.0.0",
31
- "eslint-config-airbnb": "^19.0.4",
32
- "eslint-config-prettier": "^8.5.0",
33
- "eslint-plugin-import": "^2.26.0",
34
- "eslint-plugin-jsx-a11y": "^6.6.1",
35
- "eslint-plugin-prettier": "^4.2.1",
36
- "eslint-plugin-react": "^7.32.0",
37
- "prettier": "^2.8.0"
38
- },
39
- "repository": {
40
- "type": "git",
41
- "url": "git+https://github.com/GEPROM/eslint-prettier-geprom-sapient.git"
42
- },
43
- "bugs": {
44
- "url": "https://github.com/GEPROM/eslint-prettier-geprom-sapient/issues"
45
- },
46
- "homepage": "https://github.com/GEPROM/eslint-prettier-geprom-sapient#readme"
47
- }
1
+ {
2
+ "name": "@geprom/eslint-prettier-sapient",
3
+ "version": "1.0.5",
4
+ "description": "ESLint and Prettier configuration for Geprom Sapient projects with snake_case and camelCase support",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "postinstall": "node setup.js"
8
+ },
9
+ "files": [
10
+ "index.js",
11
+ "setup.js",
12
+ "prettier-config.js"
13
+ ],
14
+ "keywords": [
15
+ "eslint",
16
+ "eslintconfig",
17
+ "prettier",
18
+ "airbnb",
19
+ "react",
20
+ "code-style",
21
+ "linter"
22
+ ],
23
+ "author": "GEPROM",
24
+ "license": "MIT",
25
+ "peerDependencies": {
26
+ "eslint": "^8.0.0",
27
+ "prettier": "^2.8.0",
28
+ "eslint-config-airbnb": "^19.0.4",
29
+ "eslint-config-prettier": "^8.5.0",
30
+ "eslint-plugin-import": "^2.26.0",
31
+ "eslint-plugin-jsx-a11y": "^6.6.1",
32
+ "eslint-plugin-prettier": "^4.2.1",
33
+ "eslint-plugin-react": "^7.32.0"
34
+ },
35
+ "devDependencies": {
36
+ "eslint": "^8.0.0",
37
+ "eslint-config-airbnb": "^19.0.4",
38
+ "eslint-config-prettier": "^8.5.0",
39
+ "eslint-plugin-import": "^2.26.0",
40
+ "eslint-plugin-jsx-a11y": "^6.6.1",
41
+ "eslint-plugin-prettier": "^4.2.1",
42
+ "eslint-plugin-react": "^7.32.0",
43
+ "prettier": "^2.8.0"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/GEPROM/eslint-prettier-geprom-sapient.git"
48
+ },
49
+ "bugs": {
50
+ "url": "https://github.com/GEPROM/eslint-prettier-geprom-sapient/issues"
51
+ },
52
+ "homepage": "https://github.com/GEPROM/eslint-prettier-geprom-sapient#readme"
53
+ }
@@ -1,18 +1,18 @@
1
- module.exports = {
2
- printWidth: 100,
3
- tabWidth: 2,
4
- useTabs: false,
5
- semi: true,
6
- singleQuote: true,
7
- quoteProps: "as-needed",
8
- jsxSingleQuote: false,
9
- trailingComma: "es5",
10
- bracketSpacing: true,
11
- bracketSameLine: false,
12
- arrowParens: "always",
13
- requirePragma: false,
14
- insertPragma: false,
15
- proseWrap: "preserve",
16
- htmlWhitespaceSensitivity: "css",
17
- endOfLine: "lf",
18
- };
1
+ module.exports = {
2
+ printWidth: 100,
3
+ tabWidth: 2,
4
+ useTabs: false,
5
+ semi: true,
6
+ singleQuote: true,
7
+ quoteProps: "as-needed",
8
+ jsxSingleQuote: false,
9
+ trailingComma: "es5",
10
+ bracketSpacing: true,
11
+ bracketSameLine: false,
12
+ arrowParens: "always",
13
+ requirePragma: false,
14
+ insertPragma: false,
15
+ proseWrap: "preserve",
16
+ htmlWhitespaceSensitivity: "css",
17
+ endOfLine: "auto",
18
+ };
package/setup.js CHANGED
@@ -1,133 +1,163 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require("fs");
4
- const path = require("path");
5
- const { spawn } = require("child_process");
6
-
7
- // Get the root directory of the project that installed this package
8
- // When installed via npm, this runs in node_modules, so we go up to find the project root
9
- const projectRoot = path.resolve(__dirname, "../../..");
10
-
11
- // Read the eslint configuration from this package
12
- const eslintConfig = require("./index.js");
13
-
14
- // Prettier configuration
15
- const prettierConfig = require("./prettier-config.js");
16
-
17
- // Create .eslintrc.js in the project root
18
- const eslintrcPath = path.join(projectRoot, ".eslintrc.js");
19
- const eslintrcContent = `module.exports = ${JSON.stringify(eslintConfig, null, 2)};`;
20
-
21
- try {
22
- fs.writeFileSync(eslintrcPath, eslintrcContent, "utf8");
23
- console.log("✓ Created .eslintrc.js");
24
- } catch (error) {
25
- console.error("Error creating .eslintrc.js:", error.message);
26
- }
27
-
28
- // Create .prettierrc.js in the project root
29
- const prettierrcPath = path.join(projectRoot, ".prettierrc.js");
30
- const prettierrcContent = `module.exports = ${JSON.stringify(prettierConfig, null, 2)};`;
31
-
32
- try {
33
- fs.writeFileSync(prettierrcPath, prettierrcContent, "utf8");
34
- console.log("✓ Created .prettierrc.js");
35
- } catch (error) {
36
- console.error("Error creating .prettierrc.js:", error.message);
37
- }
38
-
39
- // Create .eslintignore if it doesn't exist
40
- const eslintignorePath = path.join(projectRoot, ".eslintignore");
41
- if (!fs.existsSync(eslintignorePath)) {
42
- const eslintignoreContent = `node_modules/
43
- dist/
44
- build/
45
- coverage/
46
- .next/
47
- out/
48
- `;
49
- try {
50
- fs.writeFileSync(eslintignorePath, eslintignoreContent, "utf8");
51
- console.log("✓ Created .eslintignore");
52
- } catch (error) {
53
- console.error("Error creating .eslintignore:", error.message);
54
- }
55
- }
56
-
57
- // Create .prettierignore if it doesn't exist
58
- const prettierignorePath = path.join(projectRoot, ".prettierignore");
59
- if (!fs.existsSync(prettierignorePath)) {
60
- const prettierignoreContent = `node_modules/
61
- dist/
62
- build/
63
- coverage/
64
- .next/
65
- out/
66
- package-lock.json
67
- yarn.lock
68
- `;
69
- try {
70
- fs.writeFileSync(prettierignorePath, prettierignoreContent, "utf8");
71
- console.log("✓ Created .prettierignore");
72
- } catch (error) {
73
- console.error("Error creating .prettierignore:", error.message);
74
- }
75
- }
76
-
77
- // Function to run a command
78
- function runCommand(command, args, description) {
79
- return new Promise((resolve, reject) => {
80
- console.log(`\n▶ ${description}...`);
81
- const child = spawn(command, args, {
82
- cwd: projectRoot,
83
- stdio: "inherit",
84
- shell: true,
85
- });
86
-
87
- child.on("close", (code) => {
88
- if (code === 0) {
89
- console.log(`✓ ${description} completed`);
90
- resolve();
91
- } else {
92
- console.warn(`⚠ ${description} exited with code ${code}`);
93
- resolve(); // Don't reject, warn instead
94
- }
95
- });
96
-
97
- child.on("error", (error) => {
98
- console.error(`Error running ${description}:`, error.message);
99
- resolve(); // Don't reject, warn instead
100
- });
101
- });
102
- }
103
-
104
- // Run prettier and eslint if they're available
105
- async function formatAndLint() {
106
- try {
107
- // Try to run prettier
108
- await runCommand(
109
- "npx",
110
- ["prettier", "--write", "."],
111
- "Formatting with Prettier"
112
- );
113
-
114
- // Try to run eslint with --fix
115
- await runCommand("npx", ["eslint", ".", "--fix"], "Fixing with ESLint");
116
-
117
- console.log("\n✓ Setup completed successfully!");
118
- } catch (error) {
119
- console.error("Error during formatting/linting:", error.message);
120
- }
121
- }
122
-
123
- // Only run if prettier and eslint are available in the project
124
- const packageJsonPath = path.join(projectRoot, "package.json");
125
- if (fs.existsSync(packageJsonPath)) {
126
- formatAndLint().catch(() => {
127
- console.log(
128
- "\nNote: Prettier and ESLint will format files when run manually."
129
- );
130
- });
131
- } else {
132
- console.log("package.json not found. Skipping auto-formatting.");
133
- }
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { spawn } = require("child_process");
6
+
7
+ // Get the root directory of the project that installed this package
8
+ // When installed via npm, this runs in node_modules, so we go up to find the project root
9
+ const projectRoot = path.resolve(__dirname, "../../..");
10
+
11
+ // Read the eslint configuration from this package
12
+ const eslintConfig = require("./index.js");
13
+
14
+ // Prettier configuration
15
+ const prettierConfig = require("./prettier-config.js");
16
+
17
+ // Create .eslintrc.js in the project root
18
+ const eslintrcPath = path.join(projectRoot, ".eslintrc.js");
19
+ const eslintrcContent = `module.exports = ${JSON.stringify(eslintConfig, null, 2)};`;
20
+
21
+ try {
22
+ fs.writeFileSync(eslintrcPath, eslintrcContent, "utf8");
23
+ console.log("✓ Created .eslintrc.js");
24
+ } catch (error) {
25
+ console.error("Error creating .eslintrc.js:", error.message);
26
+ }
27
+
28
+ // Create .prettierrc.js in the project root
29
+ const prettierrcPath = path.join(projectRoot, ".prettierrc.js");
30
+ const prettierrcContent = `module.exports = ${JSON.stringify(prettierConfig, null, 2)};`;
31
+
32
+ try {
33
+ fs.writeFileSync(prettierrcPath, prettierrcContent, "utf8");
34
+ console.log("✓ Created .prettierrc.js");
35
+ } catch (error) {
36
+ console.error("Error creating .prettierrc.js:", error.message);
37
+ }
38
+
39
+ // Create .eslintignore if it doesn't exist
40
+ const eslintignorePath = path.join(projectRoot, ".eslintignore");
41
+ if (!fs.existsSync(eslintignorePath)) {
42
+ const eslintignoreContent = `node_modules/
43
+ dist/
44
+ build/
45
+ coverage/
46
+ .next/
47
+ out/
48
+ `;
49
+ try {
50
+ fs.writeFileSync(eslintignorePath, eslintignoreContent, "utf8");
51
+ console.log("✓ Created .eslintignore");
52
+ } catch (error) {
53
+ console.error("Error creating .eslintignore:", error.message);
54
+ }
55
+ }
56
+
57
+ // Create .prettierignore if it doesn't exist
58
+ const prettierignorePath = path.join(projectRoot, ".prettierignore");
59
+ if (!fs.existsSync(prettierignorePath)) {
60
+ const prettierignoreContent = `node_modules/
61
+ dist/
62
+ build/
63
+ coverage/
64
+ .next/
65
+ out/
66
+ package-lock.json
67
+ yarn.lock
68
+ `;
69
+ try {
70
+ fs.writeFileSync(prettierignorePath, prettierignoreContent, "utf8");
71
+ console.log("✓ Created .prettierignore");
72
+ } catch (error) {
73
+ console.error("Error creating .prettierignore:", error.message);
74
+ }
75
+ }
76
+
77
+ // Create .vscode/settings.json if it doesn't exist
78
+ const vscodeDir = path.join(projectRoot, ".vscode");
79
+ const vscodePath = path.join(vscodeDir, "settings.json");
80
+ if (!fs.existsSync(vscodePath)) {
81
+ const vscodeSettings = {
82
+ "eslint.enable": true,
83
+ "eslint.validate": ["javascript", "javascriptreact"],
84
+ "[javascript]": {
85
+ "editor.codeActionsOnSave": {
86
+ "source.fixAll.eslint": true,
87
+ },
88
+ },
89
+ "[javascriptreact]": {
90
+ "editor.codeActionsOnSave": {
91
+ "source.fixAll.eslint": true,
92
+ },
93
+ },
94
+ };
95
+ try {
96
+ // Create .vscode directory if it doesn't exist
97
+ if (!fs.existsSync(vscodeDir)) {
98
+ fs.mkdirSync(vscodeDir, { recursive: true });
99
+ }
100
+ fs.writeFileSync(vscodePath, JSON.stringify(vscodeSettings, null, 2), "utf8");
101
+ console.log("✓ Created .vscode/settings.json");
102
+ } catch (error) {
103
+ console.error("Error creating .vscode/settings.json:", error.message);
104
+ }
105
+ }
106
+
107
+ // Function to run a command
108
+ function runCommand(command, args, description) {
109
+ return new Promise((resolve, reject) => {
110
+ console.log(`\n▶ ${description}...`);
111
+ const child = spawn(command, args, {
112
+ cwd: projectRoot,
113
+ stdio: "inherit",
114
+ shell: true,
115
+ });
116
+
117
+ child.on("close", (code) => {
118
+ if (code === 0) {
119
+ console.log(`✓ ${description} completed`);
120
+ resolve();
121
+ } else {
122
+ console.warn(`⚠ ${description} exited with code ${code}`);
123
+ resolve(); // Don't reject, warn instead
124
+ }
125
+ });
126
+
127
+ child.on("error", (error) => {
128
+ console.error(`Error running ${description}:`, error.message);
129
+ resolve(); // Don't reject, warn instead
130
+ });
131
+ });
132
+ }
133
+
134
+ // Run prettier and eslint if they're available
135
+ async function formatAndLint() {
136
+ try {
137
+ // Try to run prettier
138
+ await runCommand(
139
+ "npx",
140
+ ["prettier", "--write", "."],
141
+ "Formatting with Prettier"
142
+ );
143
+
144
+ // Try to run eslint with --fix
145
+ await runCommand("npx", ["eslint", ".", "--fix"], "Fixing with ESLint");
146
+
147
+ console.log("\n✓ Setup completed successfully!");
148
+ } catch (error) {
149
+ console.error("Error during formatting/linting:", error.message);
150
+ }
151
+ }
152
+
153
+ // Only run if prettier and eslint are available in the project
154
+ const packageJsonPath = path.join(projectRoot, "package.json");
155
+ if (fs.existsSync(packageJsonPath)) {
156
+ formatAndLint().catch(() => {
157
+ console.log(
158
+ "\nNote: Prettier and ESLint will format files when run manually."
159
+ );
160
+ });
161
+ } else {
162
+ console.log("package.json not found. Skipping auto-formatting.");
163
+ }