@taiga-ui/prettier-config 0.1.3 → 0.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/CHANGELOG.md CHANGED
@@ -3,17 +3,11 @@
3
3
  All notable changes to this project will be documented in this file. See
4
4
  [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [0.1.3](https://github.com/taiga-family/taiga-ui/compare/@taiga-ui/prettier-config@0.1.1...@taiga-ui/prettier-config@0.1.3) (2023-08-14)
7
-
8
- **Note:** Version bump only for package @taiga-ui/prettier-config
9
-
10
- # Change Log
11
-
12
- All notable changes to this project will be documented in this file. See
13
- [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
14
-
15
- ## 0.1.1 (2023-08-14)
6
+ # [0.2.0](https://github.com/taiga-family/taiga-ui/compare/@taiga-ui/prettier-config@0.1.3...@taiga-ui/prettier-config@0.2.0) (2023-08-20)
16
7
 
17
8
  ### Features
18
9
 
19
- - add linters ([b35e525](https://github.com/taiga-family/taiga-ui/commit/b35e5252a2bac063696f0fd1b5accc1ac0d34a66))
10
+ - add cspell config
11
+ ([268b3fb](https://github.com/taiga-family/taiga-ui/commit/268b3fbf38a679204c1a3f16bf6f0e62c83e7b82))
12
+ - support prettier 3.x ([#2](https://github.com/taiga-family/taiga-ui/issues/2))
13
+ ([9a0aa41](https://github.com/taiga-family/taiga-ui/commit/9a0aa41bba5a343d3ca237b6793806aa3f3c9f14))
package/index.js CHANGED
@@ -1,3 +1,19 @@
1
+ const attributeOptions = {
2
+ attributeGroups: [
3
+ '$ANGULAR_STRUCTURAL_DIRECTIVE',
4
+ '$ANGULAR_ELEMENT_REF',
5
+ '$ID',
6
+ '$DEFAULT',
7
+ '$CLASS',
8
+ '$ANGULAR_ANIMATION',
9
+ '$ANGULAR_ANIMATION_INPUT',
10
+ '$ANGULAR_INPUT',
11
+ '$ANGULAR_TWO_WAY_BINDING',
12
+ '$ANGULAR_OUTPUT',
13
+ ],
14
+ attributeSort: 'ASC',
15
+ };
16
+
1
17
  module.exports = {
2
18
  $schema: 'https://json.schemastore.org/prettierrc',
3
19
  htmlWhitespaceSensitivity: 'ignore',
@@ -13,18 +29,6 @@ module.exports = {
13
29
  arrowParens: 'avoid',
14
30
  singleAttributePerLine: true,
15
31
  plugins: [require.resolve('prettier-plugin-organize-attributes')],
16
- attributeGroups: [
17
- '$ANGULAR_STRUCTURAL_DIRECTIVE',
18
- '$ANGULAR_ELEMENT_REF',
19
- '$ID',
20
- '$DEFAULT',
21
- '$CLASS',
22
- '$ANGULAR_ANIMATION',
23
- '$ANGULAR_ANIMATION_INPUT',
24
- '$ANGULAR_INPUT',
25
- '$ANGULAR_TWO_WAY_BINDING',
26
- '$ANGULAR_OUTPUT',
27
- ],
28
32
  overrides: [
29
33
  {
30
34
  files: ['*.json', '.prettierrc', '.stylelintrc'],
@@ -77,6 +81,13 @@ module.exports = {
77
81
  options: {
78
82
  parser: 'angular',
79
83
  printWidth: 120,
84
+ ...attributeOptions,
85
+ },
86
+ },
87
+ {
88
+ files: ['*.ts'],
89
+ options: {
90
+ ...attributeOptions,
80
91
  },
81
92
  },
82
93
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taiga-ui/prettier-config",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Taiga-ui prettier config",
5
5
  "keywords": [
6
6
  "prettier",
@@ -13,11 +13,11 @@
13
13
  "license": "Apache-2.0",
14
14
  "main": "index.js",
15
15
  "dependencies": {
16
- "@prettier/plugin-xml": "2.2.0",
17
- "@types/prettier": "2.7.3",
16
+ "@prettier/plugin-xml": "3.2.0",
17
+ "@types/prettier": "3.0.0",
18
18
  "prettier-package-json": "2.8.0",
19
- "prettier-plugin-organize-attributes": "0.0.5",
20
- "sort-package-json": "1.57.0"
19
+ "prettier-plugin-organize-attributes": "1.0.0",
20
+ "sort-package-json": "2.5.1"
21
21
  },
22
22
  "publishConfig": {
23
23
  "access": "public"
@@ -1,4 +1,5 @@
1
- const sortPackageJson = require('sort-package-json');
1
+ const prettier = import('prettier');
2
+ const sortPackageJson = import('sort-package-json');
2
3
  const {parsers} = require('prettier/parser-babel');
3
4
 
4
5
  const parser = parsers['json-stringify'];
@@ -6,31 +7,38 @@ const parser = parsers['json-stringify'];
6
7
  exports.parsers = {
7
8
  'json-stringify': {
8
9
  ...parser,
9
- preprocess(text, options) {
10
- const processed = parser.preprocess ? parser.preprocess(text, options) : text;
11
-
10
+ async parse(text, options) {
12
11
  const isPackageJson =
13
12
  options.filepath &&
14
13
  /package\.json$|ng-package\.json$/.test(options.filepath);
15
14
 
16
- if (isPackageJson) {
17
- const json = JSON.parse(processed);
18
- const unsortedScripts = deepClone((json && json.scripts) || {});
19
- const sorted = sortPackageJson(json);
20
-
21
- /**
22
- * @note: add the scripts field if it's provided
23
- * the scripts must be unsorted
24
- */
25
- // eslint-disable-next-line no-prototype-builtins
26
- if (json && json.hasOwnProperty('scripts')) {
27
- sorted.scripts = unsortedScripts;
28
- }
29
-
30
- return JSON.stringify(sorted);
15
+ if (!isPackageJson) {
16
+ return parser.parse(text, options);
17
+ }
18
+
19
+ // To avoid parsing errors
20
+ text = await (await prettier).format(text, {filepath: options.filepath});
21
+
22
+ if (parser.preprocess) {
23
+ text = parser.preprocess(text, options);
31
24
  }
32
25
 
33
- return processed;
26
+ const json = JSON.parse(text);
27
+ const unsortedScripts = deepClone((json && json.scripts) || {});
28
+ const sorted = (await sortPackageJson).default(json);
29
+
30
+ /**
31
+ * @note: add the scripts field if it's provided
32
+ * the scripts must be unsorted
33
+ */
34
+ // eslint-disable-next-line no-prototype-builtins
35
+ if (json && json.hasOwnProperty('scripts')) {
36
+ sorted.scripts = unsortedScripts;
37
+ }
38
+
39
+ text = JSON.stringify(sorted);
40
+
41
+ return parser.parse(text, options);
34
42
  },
35
43
  },
36
44
  };