@efolusi/meridian-guard 1.22.0 → 1.23.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/LICENSE +201 -21
- package/README.md +11 -1
- package/package.json +2 -2
- package/src/cli.mjs +9 -3
- package/src/generated/meridian-rules.json +34 -2
- package/src/index.mjs +1 -1
- package/src/reporter.mjs +5 -1
- package/src/scanner.mjs +45 -8
package/LICENSE
CHANGED
|
@@ -1,21 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Efolusi
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -33,6 +33,16 @@ npx @efolusi/meridian-guard src pages --format json
|
|
|
33
33
|
npx meridian-guard --help
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
`--fix` rewrites files in place to apply the fixes Guard knows are safe, then
|
|
37
|
+
reports what is left. Today that means deleting deprecated props the component
|
|
38
|
+
already ignores, such as Drawer `modal`. Commit first and review the diff. The
|
|
39
|
+
[migration guide](https://meridian.efolusi.com/guidelines/migration.md) says which
|
|
40
|
+
deprecations have a mechanical fix and why the others do not.
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
npx @efolusi/meridian-guard src --fix
|
|
44
|
+
```
|
|
45
|
+
|
|
36
46
|
Guard exits `0` when no diagnostics are found, `1` when a contract violation is
|
|
37
47
|
found (including warnings), and `2` for invalid options, missing targets, empty
|
|
38
48
|
scans, or runtime failures. An empty scan fails closed so a misspelled CI target
|
|
@@ -54,7 +64,7 @@ not shipped interface source.
|
|
|
54
64
|
| `MDG001` | error | Imported Meridian components must exist. |
|
|
55
65
|
| `MDG002` | error | Static `Icon` and `IconButton` names must exist. |
|
|
56
66
|
| `MDG003` | warning | Inline and CSS-in-JS colors use semantic tokens, not hex. |
|
|
57
|
-
| `MDG004` | warning | Deprecated props migrate to their canonical replacement. |
|
|
67
|
+
| `MDG004` | warning | Deprecated props migrate to their canonical replacement. Fixable with `--fix` when the prop is ignored. |
|
|
58
68
|
| `MDG005` | error | Required accessible names and dialog titles are present. |
|
|
59
69
|
| `MDG006` | error | Referenced Meridian radius tokens must exist in the generated token contract. |
|
|
60
70
|
| `MDG007` | warning | Non-zero interface radii use the shared Meridian radius hierarchy. |
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@efolusi/meridian-guard",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"description": "Static compliance checks for React applications built with the Meridian design system.",
|
|
5
|
-
"license": "
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://meridian.efolusi.com",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
package/src/cli.mjs
CHANGED
|
@@ -5,11 +5,12 @@ import { formatJson, formatPretty } from './reporter.mjs';
|
|
|
5
5
|
const HELP = `Meridian Guard — validate React code against Meridian contracts
|
|
6
6
|
|
|
7
7
|
Usage:
|
|
8
|
-
meridian-guard [path ...] [--format pretty|json] [--allow-empty]
|
|
8
|
+
meridian-guard [path ...] [--format pretty|json] [--allow-empty] [--fix]
|
|
9
9
|
|
|
10
10
|
Options:
|
|
11
11
|
--format <name> Output format: pretty (default) or json
|
|
12
12
|
--allow-empty Pass when no supported source files are found
|
|
13
|
+
--fix Rewrite files to apply safe fixes (removes ignored deprecated props)
|
|
13
14
|
--help Show this help
|
|
14
15
|
--version Show the Guard rule-pack version
|
|
15
16
|
`;
|
|
@@ -18,10 +19,15 @@ function parseArgs(argv) {
|
|
|
18
19
|
const paths = [];
|
|
19
20
|
let format = 'pretty';
|
|
20
21
|
let allowEmpty = false;
|
|
22
|
+
let fix = false;
|
|
21
23
|
for (let index = 0; index < argv.length; index += 1) {
|
|
22
24
|
const arg = argv[index];
|
|
23
25
|
if (arg === '--help' || arg === '-h') return { help: true, paths, format };
|
|
24
26
|
if (arg === '--version' || arg === '-v') return { version: true, paths, format };
|
|
27
|
+
if (arg === '--fix') {
|
|
28
|
+
fix = true;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
25
31
|
if (arg === '--allow-empty') {
|
|
26
32
|
allowEmpty = true;
|
|
27
33
|
continue;
|
|
@@ -39,7 +45,7 @@ function parseArgs(argv) {
|
|
|
39
45
|
paths.push(arg);
|
|
40
46
|
}
|
|
41
47
|
if (!['pretty', 'json'].includes(format)) throw new Error(`unknown format ${format}`);
|
|
42
|
-
return { paths, format, allowEmpty };
|
|
48
|
+
return { paths, format, allowEmpty, fix };
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
export async function main(argv, io = process) {
|
|
@@ -55,7 +61,7 @@ export async function main(argv, io = process) {
|
|
|
55
61
|
}
|
|
56
62
|
const cwd = process.cwd();
|
|
57
63
|
const targets = (options.paths.length ? options.paths : ['.']).map(target => path.resolve(cwd, target));
|
|
58
|
-
const result = await guard(targets, { contracts });
|
|
64
|
+
const result = await guard(targets, { contracts, fix: options.fix });
|
|
59
65
|
if (result.filesScanned === 0 && !options.allowEmpty) {
|
|
60
66
|
throw new Error('no supported JavaScript, TypeScript, or CSS source files found; check the target path or pass --allow-empty');
|
|
61
67
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"components": [
|
|
5
5
|
{
|
|
6
6
|
"name": "Accordion",
|
|
@@ -1743,6 +1743,8 @@
|
|
|
1743
1743
|
"accent-subtle",
|
|
1744
1744
|
"accent-subtle-border",
|
|
1745
1745
|
"accent-subtle-fg",
|
|
1746
|
+
"avatar-bg",
|
|
1747
|
+
"avatar-fg",
|
|
1746
1748
|
"border-code",
|
|
1747
1749
|
"border-control",
|
|
1748
1750
|
"border-control-hover",
|
|
@@ -1761,6 +1763,11 @@
|
|
|
1761
1763
|
"brand-900",
|
|
1762
1764
|
"brand-950",
|
|
1763
1765
|
"caramel-500",
|
|
1766
|
+
"chart-1",
|
|
1767
|
+
"chart-2",
|
|
1768
|
+
"chart-3",
|
|
1769
|
+
"chart-4",
|
|
1770
|
+
"chart-5",
|
|
1764
1771
|
"cocoa-700",
|
|
1765
1772
|
"cocoa-900",
|
|
1766
1773
|
"cocoa-950",
|
|
@@ -1808,6 +1815,19 @@
|
|
|
1808
1815
|
"media-scrim",
|
|
1809
1816
|
"media-scrim-soft",
|
|
1810
1817
|
"media-scrim-strong",
|
|
1818
|
+
"opacity-attention",
|
|
1819
|
+
"opacity-attention-edge",
|
|
1820
|
+
"opacity-banner",
|
|
1821
|
+
"opacity-banner-edge",
|
|
1822
|
+
"opacity-chip",
|
|
1823
|
+
"opacity-disabled",
|
|
1824
|
+
"opacity-increased",
|
|
1825
|
+
"opacity-kbd",
|
|
1826
|
+
"opacity-pill",
|
|
1827
|
+
"opacity-ring",
|
|
1828
|
+
"opacity-selected",
|
|
1829
|
+
"opacity-soft-hairline",
|
|
1830
|
+
"opacity-tint",
|
|
1811
1831
|
"overlay-scrim",
|
|
1812
1832
|
"peach-200",
|
|
1813
1833
|
"radius-full",
|
|
@@ -1816,6 +1836,7 @@
|
|
|
1816
1836
|
"radius-sm",
|
|
1817
1837
|
"radius-xl",
|
|
1818
1838
|
"radius-xs",
|
|
1839
|
+
"radius-xs-plus",
|
|
1819
1840
|
"sand-100",
|
|
1820
1841
|
"sand-200",
|
|
1821
1842
|
"sand-25",
|
|
@@ -1834,6 +1855,7 @@
|
|
|
1834
1855
|
"shadow-xl",
|
|
1835
1856
|
"shadow-xs",
|
|
1836
1857
|
"space-0",
|
|
1858
|
+
"space-0-5",
|
|
1837
1859
|
"space-1",
|
|
1838
1860
|
"space-10",
|
|
1839
1861
|
"space-12",
|
|
@@ -1847,6 +1869,11 @@
|
|
|
1847
1869
|
"space-5",
|
|
1848
1870
|
"space-6",
|
|
1849
1871
|
"space-8",
|
|
1872
|
+
"state-hover-on-card",
|
|
1873
|
+
"state-hover-on-panel",
|
|
1874
|
+
"state-hover-on-tab",
|
|
1875
|
+
"state-hover-on-window",
|
|
1876
|
+
"state-pressed",
|
|
1850
1877
|
"success-100",
|
|
1851
1878
|
"success-300",
|
|
1852
1879
|
"success-600",
|
|
@@ -1854,9 +1881,13 @@
|
|
|
1854
1881
|
"success-on-dark",
|
|
1855
1882
|
"surface-brand",
|
|
1856
1883
|
"surface-card",
|
|
1884
|
+
"surface-card-hover",
|
|
1857
1885
|
"surface-code",
|
|
1858
1886
|
"surface-inverse",
|
|
1887
|
+
"surface-inverse-active",
|
|
1888
|
+
"surface-inverse-hover",
|
|
1859
1889
|
"surface-page",
|
|
1890
|
+
"surface-panel",
|
|
1860
1891
|
"surface-subtle",
|
|
1861
1892
|
"surface-sunken",
|
|
1862
1893
|
"table-pad-x",
|
|
@@ -1912,7 +1943,8 @@
|
|
|
1912
1943
|
"component": "Drawer",
|
|
1913
1944
|
"prop": "modal",
|
|
1914
1945
|
"replacement": null,
|
|
1915
|
-
"message": "@deprecated Ignored: a Drawer is always modal. Passing `false` logs a development warning; the prop will be removed in the next major version."
|
|
1946
|
+
"message": "@deprecated Ignored: a Drawer is always modal. Passing `false` logs a development warning; the prop will be removed in the next major version. Migration: https://meridian.efolusi.com/guidelines/migration.md",
|
|
1947
|
+
"codemod": "remove"
|
|
1916
1948
|
}
|
|
1917
1949
|
]
|
|
1918
1950
|
}
|
package/src/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { guard, scanSource, scanStyleSource } from './scanner.mjs';
|
|
1
|
+
export { applyFixes, guard, scanSource, scanStyleSource } from './scanner.mjs';
|
|
2
2
|
export { RULES } from './rules.mjs';
|
package/src/reporter.mjs
CHANGED
|
@@ -7,6 +7,9 @@ export function formatPretty(result, cwd = process.cwd()) {
|
|
|
7
7
|
});
|
|
8
8
|
const errors = result.diagnostics.filter(item => item.severity === 'error').length;
|
|
9
9
|
const warnings = result.diagnostics.length - errors;
|
|
10
|
+
if (result.fixed) lines.push(`Meridian Guard fixed ${result.fixed} issue(s).`);
|
|
11
|
+
const fixable = result.diagnostics.filter(item => item.fix).length;
|
|
12
|
+
if (fixable) lines.push(`${fixable} of these can be fixed with --fix.`);
|
|
10
13
|
lines.push(
|
|
11
14
|
result.diagnostics.length
|
|
12
15
|
? `\nMeridian Guard found ${errors} error(s) and ${warnings} warning(s) in ${result.filesScanned} file(s).`
|
|
@@ -21,6 +24,7 @@ export function formatJson(result) {
|
|
|
21
24
|
filesScanned: result.filesScanned,
|
|
22
25
|
errors: result.diagnostics.filter(item => item.severity === 'error').length,
|
|
23
26
|
warnings: result.diagnostics.filter(item => item.severity === 'warning').length,
|
|
24
|
-
|
|
27
|
+
...(result.fixed === undefined ? {} : { fixed: result.fixed }),
|
|
28
|
+
diagnostics: result.diagnostics.map(({ fix, ...item }) => (fix ? { ...item, fixable: true } : item)),
|
|
25
29
|
}, null, 2)}\n`;
|
|
26
30
|
}
|
package/src/scanner.mjs
CHANGED
|
@@ -152,6 +152,29 @@ function rawColorContext(node, ancestors) {
|
|
|
152
152
|
return false;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
// Deletes a JSX attribute and the whitespace before it, so
|
|
156
|
+
// `<Drawer\n modal={false}\n open>` becomes `<Drawer\n open>`.
|
|
157
|
+
function removeAttribute(source, item) {
|
|
158
|
+
let start = item.start;
|
|
159
|
+
while (start > 0 && /\s/.test(source[start - 1])) start -= 1;
|
|
160
|
+
return { start, end: item.end, text: '' };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Applies the `fix` edits carried by diagnostics; overlapping edits keep the first. */
|
|
164
|
+
export function applyFixes(source, diagnostics) {
|
|
165
|
+
const edits = diagnostics.map(item => item.fix).filter(Boolean).sort((a, b) => b.start - a.start);
|
|
166
|
+
let output = source;
|
|
167
|
+
let floor = Infinity;
|
|
168
|
+
let applied = 0;
|
|
169
|
+
for (const edit of edits) {
|
|
170
|
+
if (edit.end > floor) continue;
|
|
171
|
+
output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);
|
|
172
|
+
floor = edit.start;
|
|
173
|
+
applied += 1;
|
|
174
|
+
}
|
|
175
|
+
return { output, applied };
|
|
176
|
+
}
|
|
177
|
+
|
|
155
178
|
export function scanSource(source, file, contracts) {
|
|
156
179
|
let ast;
|
|
157
180
|
try {
|
|
@@ -242,10 +265,12 @@ export function scanSource(source, file, contracts) {
|
|
|
242
265
|
if (item.type !== 'JSXAttribute') continue;
|
|
243
266
|
const contract = deprecated.get(`${component}:${item.name.name}`);
|
|
244
267
|
if (!contract) continue;
|
|
245
|
-
|
|
268
|
+
const found = diagnostic(file, item, RULES.deprecatedApi,
|
|
246
269
|
contract.replacement
|
|
247
270
|
? `<${component}> prop "${contract.prop}" is deprecated; use "${contract.replacement}".`
|
|
248
|
-
: `<${component}> prop "${contract.prop}" is deprecated. ${contract.message}`)
|
|
271
|
+
: `<${component}> prop "${contract.prop}" is deprecated. ${contract.message}`);
|
|
272
|
+
if (contract.codemod === 'remove') found.fix = removeAttribute(source, item);
|
|
273
|
+
diagnostics.push(found);
|
|
249
274
|
}
|
|
250
275
|
|
|
251
276
|
if (component === 'IconButton' && !attribute(node, 'label')) {
|
|
@@ -358,15 +383,27 @@ export function scanStyleSource(source, file, contracts) {
|
|
|
358
383
|
return diagnostics;
|
|
359
384
|
}
|
|
360
385
|
|
|
361
|
-
export async function guard(targets, { contracts = defaultContracts } = {}) {
|
|
386
|
+
export async function guard(targets, { contracts = defaultContracts, fix = false } = {}) {
|
|
362
387
|
const files = await collectFiles(targets);
|
|
363
388
|
const diagnostics = [];
|
|
389
|
+
let fixed = 0;
|
|
364
390
|
for (const file of files) {
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
391
|
+
const scan = text => (path.extname(file) === '.css'
|
|
392
|
+
? scanStyleSource(text, file, contracts)
|
|
393
|
+
: scanSource(text, file, contracts));
|
|
394
|
+
let source = await fs.readFile(file, 'utf8');
|
|
395
|
+
let found = scan(source);
|
|
396
|
+
if (fix && found.some(item => item.fix)) {
|
|
397
|
+
const result = applyFixes(source, found);
|
|
398
|
+
await fs.writeFile(file, result.output);
|
|
399
|
+
fixed += result.applied;
|
|
400
|
+
source = result.output;
|
|
401
|
+
found = scan(source);
|
|
402
|
+
}
|
|
403
|
+
diagnostics.push(...found);
|
|
369
404
|
}
|
|
370
405
|
diagnostics.sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column || a.ruleId.localeCompare(b.ruleId));
|
|
371
|
-
return
|
|
406
|
+
return fix
|
|
407
|
+
? { filesScanned: files.length, fixed, diagnostics }
|
|
408
|
+
: { filesScanned: files.length, diagnostics };
|
|
372
409
|
}
|