@vheissulabs/prettier-config 1.3.0 → 1.7.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/README.md +45 -15
- package/bin/init.js +35 -13
- package/eslint.config.js +52 -0
- package/package.json +22 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @vheissulabs/prettier-config
|
|
2
2
|
|
|
3
|
-
Shared Prettier configuration for VheissuLabs projects.
|
|
3
|
+
Shared Prettier and ESLint configuration for VheissuLabs projects.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ Shared Prettier configuration for VheissuLabs projects.
|
|
|
8
8
|
npm install --save-dev @vheissulabs/prettier-config
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
## Usage
|
|
11
|
+
## Prettier Usage
|
|
12
12
|
|
|
13
13
|
Run the init script to automatically add the config to your package.json:
|
|
14
14
|
|
|
@@ -24,13 +24,7 @@ Or manually add to your `package.json`:
|
|
|
24
24
|
}
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
```js
|
|
30
|
-
module.exports = require('@vheissulabs/prettier-config')
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### Extending the config
|
|
27
|
+
### Extending Prettier config
|
|
34
28
|
|
|
35
29
|
```js
|
|
36
30
|
module.exports = {
|
|
@@ -39,16 +33,52 @@ module.exports = {
|
|
|
39
33
|
}
|
|
40
34
|
```
|
|
41
35
|
|
|
36
|
+
## ESLint Usage (Vue)
|
|
37
|
+
|
|
38
|
+
Install peer dependencies:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install --save-dev eslint eslint-plugin-vue
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Create `eslint.config.js` in your project:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
const vheissuConfig = require('@vheissulabs/prettier-config/eslint')
|
|
48
|
+
|
|
49
|
+
module.exports = [
|
|
50
|
+
...vheissuConfig,
|
|
51
|
+
// Your overrides here
|
|
52
|
+
]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### What ESLint enforces
|
|
56
|
+
|
|
57
|
+
Forces Vue template content to new lines:
|
|
58
|
+
|
|
59
|
+
```vue
|
|
60
|
+
<!-- Before (Prettier output) -->
|
|
61
|
+
<PrimaryButton @click="save">Save</PrimaryButton>
|
|
62
|
+
|
|
63
|
+
<!-- After (ESLint fix) -->
|
|
64
|
+
<PrimaryButton @click="save">
|
|
65
|
+
Save
|
|
66
|
+
</PrimaryButton>
|
|
67
|
+
```
|
|
68
|
+
|
|
42
69
|
## What's included
|
|
43
70
|
|
|
71
|
+
### Prettier
|
|
44
72
|
- 4 space indentation
|
|
45
73
|
- No semicolons
|
|
46
74
|
- Single quotes
|
|
47
75
|
- Vue script/style indentation
|
|
48
76
|
- Single attribute per line
|
|
49
|
-
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
77
|
+
- HTML whitespace sensitivity: ignore
|
|
78
|
+
- Import sorting (no blank lines between groups)
|
|
79
|
+
|
|
80
|
+
### ESLint (Vue)
|
|
81
|
+
- Single-line element content forced to new line
|
|
82
|
+
- Closing bracket on new line for multiline elements
|
|
83
|
+
- Max 1 attribute per line
|
|
84
|
+
- 4 space HTML indentation
|
package/bin/init.js
CHANGED
|
@@ -12,22 +12,44 @@ if (!fs.existsSync(packageJsonPath)) {
|
|
|
12
12
|
|
|
13
13
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
|
|
14
14
|
|
|
15
|
+
// Detect if project uses ES modules
|
|
16
|
+
const isESModule = packageJson.type === 'module'
|
|
17
|
+
const eslintExt = isESModule ? 'cjs' : 'js'
|
|
18
|
+
const eslintConfigPath = path.join(process.cwd(), `eslint.config.${eslintExt}`)
|
|
19
|
+
|
|
20
|
+
// Check for existing eslint config (either .js or .cjs)
|
|
21
|
+
const existingConfigs = ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
|
|
22
|
+
.map(f => path.join(process.cwd(), f))
|
|
23
|
+
.filter(f => fs.existsSync(f))
|
|
24
|
+
|
|
25
|
+
// Add Prettier config
|
|
15
26
|
if (packageJson.prettier) {
|
|
16
27
|
console.log('⚠️ Prettier config already exists in package.json')
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
28
|
+
} else {
|
|
29
|
+
packageJson.prettier = '@vheissulabs/prettier-config'
|
|
20
30
|
|
|
21
|
-
|
|
31
|
+
const originalContent = fs.readFileSync(packageJsonPath, 'utf8')
|
|
32
|
+
const indent = originalContent.match(/^(\s+)/m)?.[1] || ' '
|
|
22
33
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
34
|
+
fs.writeFileSync(
|
|
35
|
+
packageJsonPath,
|
|
36
|
+
JSON.stringify(packageJson, null, indent.length) + '\n'
|
|
37
|
+
)
|
|
38
|
+
console.log('✅ Added prettier config to package.json')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Add ESLint config
|
|
42
|
+
if (existingConfigs.length > 0) {
|
|
43
|
+
console.log(`⚠️ ESLint config already exists: ${path.basename(existingConfigs[0])}`)
|
|
44
|
+
} else {
|
|
45
|
+
const eslintConfig = `const vheissuConfig = require('@vheissulabs/prettier-config/eslint')
|
|
26
46
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
)
|
|
47
|
+
module.exports = [...vheissuConfig]
|
|
48
|
+
`
|
|
49
|
+
fs.writeFileSync(eslintConfigPath, eslintConfig)
|
|
50
|
+
console.log(`✅ Created eslint.config.${eslintExt}${isESModule ? ' (CommonJS for ES module project)' : ''}`)
|
|
51
|
+
}
|
|
31
52
|
|
|
32
|
-
console.log('
|
|
33
|
-
console.log('
|
|
53
|
+
console.log('')
|
|
54
|
+
console.log('📦 Install peer dependencies:')
|
|
55
|
+
console.log(' npm install --save-dev eslint eslint-plugin-vue typescript-eslint')
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const vue = require('eslint-plugin-vue')
|
|
2
|
+
|
|
3
|
+
// Try to load typescript-eslint if available
|
|
4
|
+
let tseslint = null
|
|
5
|
+
try {
|
|
6
|
+
tseslint = require('typescript-eslint')
|
|
7
|
+
} catch (e) {
|
|
8
|
+
// typescript-eslint not installed, skip TS support
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const baseConfig = [
|
|
12
|
+
...vue.configs['flat/recommended'],
|
|
13
|
+
{
|
|
14
|
+
rules: {
|
|
15
|
+
// Force element content to new line
|
|
16
|
+
'vue/singleline-html-element-content-newline': ['error', {
|
|
17
|
+
ignoreWhenNoAttributes: false,
|
|
18
|
+
ignoreWhenEmpty: true,
|
|
19
|
+
}],
|
|
20
|
+
// Force closing bracket to new line
|
|
21
|
+
'vue/html-closing-bracket-newline': ['error', {
|
|
22
|
+
singleline: 'never',
|
|
23
|
+
multiline: 'always',
|
|
24
|
+
}],
|
|
25
|
+
// Max attributes per line
|
|
26
|
+
'vue/max-attributes-per-line': ['error', {
|
|
27
|
+
singleline: 1,
|
|
28
|
+
multiline: 1,
|
|
29
|
+
}],
|
|
30
|
+
// Consistent indentation in templates
|
|
31
|
+
'vue/html-indent': ['error', 4],
|
|
32
|
+
// Disable rules that conflict with Prettier
|
|
33
|
+
'vue/html-self-closing': 'off',
|
|
34
|
+
// Allow single-word component names (common in page components)
|
|
35
|
+
'vue/multi-word-component-names': 'off',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
// Add TypeScript support for Vue files if typescript-eslint is available
|
|
41
|
+
if (tseslint) {
|
|
42
|
+
baseConfig.push({
|
|
43
|
+
files: ['**/*.vue'],
|
|
44
|
+
languageOptions: {
|
|
45
|
+
parserOptions: {
|
|
46
|
+
parser: tseslint.parser,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = baseConfig
|
package/package.json
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vheissulabs/prettier-config",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Shared Prettier configuration for VheissuLabs projects",
|
|
3
|
+
"version": "1.7.0",
|
|
4
|
+
"description": "Shared Prettier and ESLint configuration for VheissuLabs projects",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./index.js",
|
|
8
|
+
"./eslint": "./eslint.config.js"
|
|
9
|
+
},
|
|
6
10
|
"bin": {
|
|
7
11
|
"vheissu-prettier-init": "./bin/init.js"
|
|
8
12
|
},
|
|
9
13
|
"keywords": [
|
|
10
14
|
"prettier",
|
|
15
|
+
"eslint",
|
|
11
16
|
"config",
|
|
12
17
|
"vheissulabs",
|
|
13
|
-
"tailwindcss"
|
|
18
|
+
"tailwindcss",
|
|
19
|
+
"vue"
|
|
14
20
|
],
|
|
15
21
|
"author": "Karl Miller",
|
|
16
22
|
"license": "MIT",
|
|
@@ -20,11 +26,23 @@
|
|
|
20
26
|
},
|
|
21
27
|
"peerDependencies": {
|
|
22
28
|
"prettier": ">=3.0.0",
|
|
23
|
-
"prettier-plugin-tailwindcss": ">=0.5.0"
|
|
29
|
+
"prettier-plugin-tailwindcss": ">=0.5.0",
|
|
30
|
+
"eslint": ">=9.0.0",
|
|
31
|
+
"eslint-plugin-vue": ">=9.0.0",
|
|
32
|
+
"typescript-eslint": ">=8.0.0"
|
|
24
33
|
},
|
|
25
34
|
"peerDependenciesMeta": {
|
|
26
35
|
"prettier-plugin-tailwindcss": {
|
|
27
36
|
"optional": true
|
|
37
|
+
},
|
|
38
|
+
"eslint": {
|
|
39
|
+
"optional": true
|
|
40
|
+
},
|
|
41
|
+
"eslint-plugin-vue": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"typescript-eslint": {
|
|
45
|
+
"optional": true
|
|
28
46
|
}
|
|
29
47
|
},
|
|
30
48
|
"dependencies": {
|