@itstandu/code-style 1.1.1 → 1.2.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 +59 -12
- package/index.mjs +19 -0
- package/package.json +14 -4
- package/prettier/index.mjs +49 -0
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ Production-ready shared ESLint + Prettier configuration library for JavaScript a
|
|
|
11
11
|
- **Prettier v3** with Tailwind CSS support
|
|
12
12
|
- Supports **JavaScript** and **TypeScript**
|
|
13
13
|
- **Full file type support** - Formats all common file types: JS/JSX, TS/TSX, JSON, CSS/SCSS/LESS, HTML, Markdown, YAML, GraphQL, and more
|
|
14
|
+
- **Dual package exports** - Supports both CommonJS (`require`) and ES modules (`import`)
|
|
14
15
|
- Framework presets: **React**, **Next.js**, **Vue**, **Angular**, **NestJS**
|
|
15
16
|
- **Node.js** backend support
|
|
16
17
|
- Stable import sorting with `eslint-plugin-simple-import-sort`
|
|
@@ -55,16 +56,18 @@ After installation, you only need to configure **2 files** to get started:
|
|
|
55
56
|
|
|
56
57
|
### 1. ESLint Config
|
|
57
58
|
|
|
58
|
-
Create `eslint.config.js` (or `eslint.config.mjs`) in your project root:
|
|
59
|
+
Create `eslint.config.js` (CommonJS) or `eslint.config.mjs` (ES modules) in your project root:
|
|
59
60
|
|
|
60
|
-
**
|
|
61
|
+
**CommonJS (`eslint.config.js`):**
|
|
62
|
+
|
|
63
|
+
For TypeScript projects:
|
|
61
64
|
```javascript
|
|
62
65
|
const codeStyle = require('@itstandu/code-style')
|
|
63
66
|
|
|
64
67
|
module.exports = [codeStyle.recommended, codeStyle.typescript, codeStyle.node]
|
|
65
68
|
```
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
For React/Next.js:
|
|
68
71
|
```javascript
|
|
69
72
|
const codeStyle = require('@itstandu/code-style')
|
|
70
73
|
|
|
@@ -72,30 +75,38 @@ module.exports = [codeStyle.recommended, codeStyle.typescript, codeStyle.react]
|
|
|
72
75
|
// or codeStyle.next for Next.js
|
|
73
76
|
```
|
|
74
77
|
|
|
75
|
-
**
|
|
78
|
+
**ES Modules (`eslint.config.mjs`):**
|
|
79
|
+
|
|
80
|
+
For TypeScript projects:
|
|
76
81
|
```javascript
|
|
77
|
-
|
|
82
|
+
import codeStyle from '@itstandu/code-style'
|
|
78
83
|
|
|
79
|
-
|
|
84
|
+
export default [codeStyle.recommended, codeStyle.typescript, codeStyle.node]
|
|
80
85
|
```
|
|
81
86
|
|
|
82
|
-
|
|
87
|
+
For React/Next.js:
|
|
83
88
|
```javascript
|
|
84
|
-
|
|
89
|
+
import codeStyle from '@itstandu/code-style'
|
|
85
90
|
|
|
86
|
-
|
|
91
|
+
export default [codeStyle.recommended, codeStyle.typescript, codeStyle.react]
|
|
92
|
+
// or codeStyle.next for Next.js
|
|
87
93
|
```
|
|
88
94
|
|
|
89
95
|
### 2. Prettier Config
|
|
90
96
|
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
**CommonJS (`.prettierrc.js` or `.prettierrc.cjs`):**
|
|
93
98
|
```javascript
|
|
94
99
|
module.exports = require('@itstandu/code-style/prettier')
|
|
95
100
|
```
|
|
96
101
|
|
|
97
|
-
|
|
102
|
+
**ES Modules (`.prettierrc.mjs`):**
|
|
103
|
+
```javascript
|
|
104
|
+
import prettierConfig from '@itstandu/code-style/prettier'
|
|
105
|
+
|
|
106
|
+
export default prettierConfig
|
|
107
|
+
```
|
|
98
108
|
|
|
109
|
+
**Or add to `package.json`:**
|
|
99
110
|
```json
|
|
100
111
|
{
|
|
101
112
|
"prettier": "@itstandu/code-style/prettier"
|
|
@@ -106,23 +117,59 @@ Or add to `package.json`:
|
|
|
106
117
|
|
|
107
118
|
## Usage
|
|
108
119
|
|
|
120
|
+
### CommonJS vs ES Modules
|
|
121
|
+
|
|
122
|
+
This package supports both CommonJS and ES modules:
|
|
123
|
+
|
|
124
|
+
- **CommonJS**: Use `require()` and `module.exports` (works with `.js` files)
|
|
125
|
+
- **ES Modules**: Use `import` and `export` (works with `.mjs` files or `"type": "module"`)
|
|
126
|
+
|
|
127
|
+
The package automatically resolves to the correct format based on your import style.
|
|
128
|
+
|
|
109
129
|
### Available Presets
|
|
110
130
|
|
|
111
131
|
#### Base Preset (Minimal)
|
|
132
|
+
|
|
133
|
+
**CommonJS:**
|
|
112
134
|
```javascript
|
|
135
|
+
const codeStyle = require('@itstandu/code-style')
|
|
113
136
|
module.exports = [codeStyle.base, codeStyle.typescript, codeStyle.node]
|
|
114
137
|
```
|
|
115
138
|
|
|
139
|
+
**ES Modules:**
|
|
140
|
+
```javascript
|
|
141
|
+
import codeStyle from '@itstandu/code-style'
|
|
142
|
+
export default [codeStyle.base, codeStyle.typescript, codeStyle.node]
|
|
143
|
+
```
|
|
144
|
+
|
|
116
145
|
#### Recommended Preset (Default, Better Safety)
|
|
146
|
+
|
|
147
|
+
**CommonJS:**
|
|
117
148
|
```javascript
|
|
149
|
+
const codeStyle = require('@itstandu/code-style')
|
|
118
150
|
module.exports = [codeStyle.recommended, codeStyle.typescript, codeStyle.node]
|
|
119
151
|
```
|
|
120
152
|
|
|
153
|
+
**ES Modules:**
|
|
154
|
+
```javascript
|
|
155
|
+
import codeStyle from '@itstandu/code-style'
|
|
156
|
+
export default [codeStyle.recommended, codeStyle.typescript, codeStyle.node]
|
|
157
|
+
```
|
|
158
|
+
|
|
121
159
|
#### Strict Preset (Opt-in, includes boundaries)
|
|
160
|
+
|
|
161
|
+
**CommonJS:**
|
|
122
162
|
```javascript
|
|
163
|
+
const codeStyle = require('@itstandu/code-style')
|
|
123
164
|
module.exports = [codeStyle.strict, codeStyle.typescript, codeStyle.node]
|
|
124
165
|
```
|
|
125
166
|
|
|
167
|
+
**ES Modules:**
|
|
168
|
+
```javascript
|
|
169
|
+
import codeStyle from '@itstandu/code-style'
|
|
170
|
+
export default [codeStyle.strict, codeStyle.typescript, codeStyle.node]
|
|
171
|
+
```
|
|
172
|
+
|
|
126
173
|
### Framework Presets
|
|
127
174
|
|
|
128
175
|
- **React**: `codeStyle.react`
|
package/index.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createRequire } from 'module'
|
|
2
|
+
import { fileURLToPath } from 'url'
|
|
3
|
+
import { dirname, join } from 'path'
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
6
|
+
const __dirname = dirname(__filename)
|
|
7
|
+
const require = createRequire(import.meta.url)
|
|
8
|
+
|
|
9
|
+
export const base = require(join(__dirname, 'eslint', 'base.js'))
|
|
10
|
+
export const javascript = require(join(__dirname, 'eslint', 'javascript.js'))
|
|
11
|
+
export const typescript = require(join(__dirname, 'eslint', 'typescript.js'))
|
|
12
|
+
export const node = require(join(__dirname, 'eslint', 'node.js'))
|
|
13
|
+
export const react = require(join(__dirname, 'eslint', 'react.js'))
|
|
14
|
+
export const next = require(join(__dirname, 'eslint', 'next.js'))
|
|
15
|
+
export const vue = require(join(__dirname, 'eslint', 'vue.js'))
|
|
16
|
+
export const angular = require(join(__dirname, 'eslint', 'angular.js'))
|
|
17
|
+
export const nest = require(join(__dirname, 'eslint', 'nest.js'))
|
|
18
|
+
export const recommended = require(join(__dirname, 'eslint', 'recommended.js'))
|
|
19
|
+
export const strict = require(join(__dirname, 'eslint', 'strict.js'))
|
package/package.json
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itstandu/code-style",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Production-ready shared ESLint + Prettier configuration for JavaScript and TypeScript projects",
|
|
5
5
|
"type": "commonjs",
|
|
6
|
-
"main": "index.js",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"module": "./index.mjs",
|
|
7
8
|
"exports": {
|
|
8
|
-
".":
|
|
9
|
-
|
|
9
|
+
".": {
|
|
10
|
+
"require": "./index.js",
|
|
11
|
+
"import": "./index.mjs",
|
|
12
|
+
"default": "./index.js"
|
|
13
|
+
},
|
|
14
|
+
"./prettier": {
|
|
15
|
+
"require": "./prettier/index.cjs",
|
|
16
|
+
"import": "./prettier/index.mjs",
|
|
17
|
+
"default": "./prettier/index.cjs"
|
|
18
|
+
}
|
|
10
19
|
},
|
|
11
20
|
"files": [
|
|
12
21
|
"eslint",
|
|
13
22
|
"prettier",
|
|
14
23
|
"index.js",
|
|
24
|
+
"index.mjs",
|
|
15
25
|
"README.md",
|
|
16
26
|
".prettierignore"
|
|
17
27
|
],
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
// Basic formatting
|
|
3
|
+
semi: true,
|
|
4
|
+
singleQuote: true,
|
|
5
|
+
trailingComma: 'all',
|
|
6
|
+
printWidth: 80,
|
|
7
|
+
tabWidth: 2,
|
|
8
|
+
useTabs: false,
|
|
9
|
+
|
|
10
|
+
// Bracket and spacing
|
|
11
|
+
bracketSpacing: true,
|
|
12
|
+
bracketSameLine: false,
|
|
13
|
+
arrowParens: 'always',
|
|
14
|
+
|
|
15
|
+
// JSX/HTML specific
|
|
16
|
+
jsxSingleQuote: false,
|
|
17
|
+
singleAttributePerLine: false,
|
|
18
|
+
|
|
19
|
+
// Quotes
|
|
20
|
+
quoteProps: 'as-needed',
|
|
21
|
+
|
|
22
|
+
// Line endings and whitespace
|
|
23
|
+
endOfLine: 'lf',
|
|
24
|
+
proseWrap: 'preserve',
|
|
25
|
+
htmlWhitespaceSensitivity: 'css',
|
|
26
|
+
|
|
27
|
+
// Vue specific
|
|
28
|
+
vueIndentScriptAndStyle: false,
|
|
29
|
+
|
|
30
|
+
// Pragma (for legacy systems)
|
|
31
|
+
insertPragma: false,
|
|
32
|
+
requirePragma: false,
|
|
33
|
+
|
|
34
|
+
// Embedded language formatting
|
|
35
|
+
embeddedLanguageFormatting: 'auto',
|
|
36
|
+
|
|
37
|
+
// XML/SVG specific options
|
|
38
|
+
xmlQuoteAttributes: 'preserve',
|
|
39
|
+
xmlSelfClosingSpace: true,
|
|
40
|
+
xmlSortAttributesByKey: false,
|
|
41
|
+
xmlWhitespaceSensitivity: 'strict',
|
|
42
|
+
|
|
43
|
+
// Plugins - order matters: oxc first for parsing, tailwindcss last for class sorting
|
|
44
|
+
plugins: [
|
|
45
|
+
'@prettier/plugin-oxc',
|
|
46
|
+
'@prettier/plugin-xml',
|
|
47
|
+
'prettier-plugin-tailwindcss',
|
|
48
|
+
],
|
|
49
|
+
}
|