Skip to content

Commit e659f4b

Browse files
Expand import order and add style groups in Prettier config (#28)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Expanded support for additional import path alias formats in code formatting. - Added new style-related import groups for improved import order handling. - **Chores** - Updated documentation to clarify usage of Prettier configurations for CommonJS and ES Module projects. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents c01dd40 + fb797dc commit e659f4b

File tree

5 files changed

+58
-23
lines changed

5 files changed

+58
-23
lines changed

.changeset/eighty-jeans-train.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@tcd-devkit/prettier-config-react': minor
3+
'@tcd-devkit/prettier-config': minor
4+
---
5+
6+
Update README with better info

.changeset/polite-teeth-change.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tcd-devkit/prettier-config': patch
3+
---
4+
5+
Add more alternative for import order path aliases and add styles aliases

packages/prettier/prettier-config-react/README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,30 @@ Alternatively, you can create a Prettier configuration file (e.g., `.prettierrc.
4343

4444
**`.prettierrc.js` (or `prettier.config.js`)**
4545

46-
This package exports both CommonJS (CJS) and ES Module (ESM) formats. You can import it accordingly:
46+
This package exports both CommonJS (CJS) and ES Module (ESM) formats. Choose the appropriate example based on your project's module system:
47+
48+
> **Note**: You can also use `prettier.config.cjs` to force CommonJS format even in projects with `"type": "module"` in package.json.
49+
50+
For CommonJS (`.js` files without `"type": "module"` in package.json):
4751

4852
```javascript
49-
// For CommonJS (e.g., if your prettier.config.js is a .js file treated as CJS)
50-
// const prettierConfigReact = require('@tcd-devkit/prettier-config-react');
53+
const prettierConfigReact = require('@tcd-devkit/prettier-config-react');
54+
55+
module.exports = {
56+
...prettierConfigReact,
57+
// Your custom overrides can be added here
58+
// For example, if you have custom Tailwind settings:
59+
// tailwindConfig: './tailwind.config.js',
60+
};
61+
```
5162

52-
// For ES Modules (e.g., if your prettier.config.js is a .mjs file or package.json has "type": "module")
53-
// import prettierConfigReact from '@tcd-devkit/prettier-config-react';
63+
For ES Modules (`.mjs` files or `.js` files with `"type": "module"` in package.json):
64+
65+
```javascript
66+
import prettierConfigReact from '@tcd-devkit/prettier-config-react';
5467

55-
// Then spread the imported config:
5668
export default {
57-
// ...prettierConfigReact, // Choose one of the import methods above
58-
...require('@tcd-devkit/prettier-config-react'), // Defaulting to require for wider compatibility in basic .js files
69+
...prettierConfigReact,
5970
// Your custom overrides can be added here
6071
// For example, if you have custom Tailwind settings:
6172
// tailwindConfig: './tailwind.config.js',

packages/prettier/prettier-config/README.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,32 @@ Alternatively, you can create a Prettier configuration file (e.g., `.prettierrc.
4747

4848
**`.prettierrc.js` (or `prettier.config.js`)**
4949

50-
This package exports both CommonJS (CJS) and ES Module (ESM) formats. You can import it accordingly:
50+
This package exports both CommonJS (CJS) and ES Module (ESM) formats. Choose the appropriate example based on your project's module system:
51+
52+
> **Note**: You can also use `prettier.config.cjs` to force CommonJS format even in projects with `"type": "module"` in package.json.
53+
54+
For CommonJS (`.js` files without `"type": "module"` in package.json):
5155

5256
```javascript
53-
// For CommonJS (e.g., if your prettier.config.js is a .js file treated as CJS)
54-
// const prettierConfig = require('@tcd-devkit/prettier-config');
57+
const prettierConfig = require('@tcd-devkit/prettier-config');
5558

56-
// For ES Modules (e.g., if your prettier.config.js is a .mjs file or package.json has "type": "module")
57-
// import prettierConfig from '@tcd-devkit/prettier-config';
59+
module.exports = {
60+
...prettierConfig,
61+
// Your custom overrides can be added here
62+
// For example:
63+
// printWidth: 100,
64+
};
65+
```
66+
67+
For ES Modules (`.mjs` files or `.js` files with `"type": "module"` in package.json):
68+
69+
```javascript
70+
import prettierConfig from '@tcd-devkit/prettier-config';
5871

59-
// Then spread the imported config:
6072
export default {
61-
// ...prettierConfig, // Choose one of the import methods above
62-
...require('@tcd-devkit/prettier-config'), // Defaulting to require for wider compatibility in basic .js files
73+
...prettierConfig,
6374
// Your custom overrides can be added here
64-
// مثلا:
75+
// For example:
6576
// printWidth: 100,
6677
};
6778
```

packages/prettier/prettier-config/src/base.formatter.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,21 @@ const baseFormatter = {
4545
'',
4646
'^(@tcd-devkit)(/.*)$',
4747
'',
48-
'^(@/shared|#shared)(/.*)$',
48+
'^(@shared|@/shared|#shared)(/.*)$',
4949
'',
50-
'^(@/server|#server)(/.*)$',
51-
'^(@/actions|#actions)(/.*)$',
50+
'^(@server|@/server|#server)(/.*)$',
51+
'^(@actions|@/actions|#actions)(/.*)$',
5252
'',
53-
'^(@/client|#client)(/.*)$',
53+
'^(@client|@/client|#client)(/.*)$',
5454
'',
55-
'^(@/components|#components)(/.*)$',
55+
'^(@components|@/components|#components)(/.*)$',
5656
'',
57-
'^(@/public|#public)(/.*)$',
57+
'^(@public|@/public|#public)(/.*)$',
5858
'',
5959
'^#([^/].*)$',
6060
'',
61+
'^(@global-styles?|@/global-styles?|#global-styles?)(/.*)$',
62+
'^(@styles?|@/styles?|#styles?)(/.*)$',
6163
'(?:\\.s?css)',
6264
'',
6365
'^[./]',

0 commit comments

Comments
 (0)