@mpfrontend/workspace-config 0.0.0-stage → 1.0.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 +202 -0
- package/README.md +84 -2
- package/dist/colors.d.ts +24 -0
- package/dist/colors.js +113 -0
- package/dist/colors.js.map +1 -0
- package/dist/eslint-core.d.ts +52 -0
- package/dist/eslint-core.js +105 -0
- package/dist/eslint-core.js.map +1 -0
- package/dist/eslint.d.ts +1 -0
- package/dist/eslint.js +2 -0
- package/dist/eslint.js.map +1 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +3 -0
- package/dist/internal.js.map +1 -0
- package/dist/prettier.d.ts +12 -0
- package/dist/prettier.js +13 -0
- package/dist/prettier.js.map +1 -0
- package/dist/rules/logical-properties.d.ts +8 -0
- package/dist/rules/logical-properties.js +154 -0
- package/dist/rules/logical-properties.js.map +1 -0
- package/dist/rules/no-handwritten-css.d.ts +8 -0
- package/dist/rules/no-handwritten-css.js +91 -0
- package/dist/rules/no-handwritten-css.js.map +1 -0
- package/dist/rules/no-literal-text.d.ts +5 -0
- package/dist/rules/no-literal-text.js +104 -0
- package/dist/rules/no-literal-text.js.map +1 -0
- package/dist/rules/no-raw-color.d.ts +3 -0
- package/dist/rules/no-raw-color.js +144 -0
- package/dist/rules/no-raw-color.js.map +1 -0
- package/dist/rules/public-entry.d.ts +9 -0
- package/dist/rules/public-entry.js +58 -0
- package/dist/rules/public-entry.js.map +1 -0
- package/package.json +44 -3
- package/tsconfig/base.json +12 -0
- package/tsconfig/library.json +11 -0
- package/tsconfig/next.json +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,85 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mpfrontend/workspace-config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Part of [MP Frontend](https://github.com/panahister/mpfrontend), released to the public npm registry as one cohort under one version.
|
|
4
|
+
Runtime: tooling. The shared quality profile of a consumer workspace: one
|
|
5
|
+
ESLint flat configuration, one Prettier profile and the TypeScript presets that every generated app and
|
|
6
|
+
package extends. It is versioned with the rest of the MP Frontend cohort, so a workspace upgrades its
|
|
7
|
+
rules by upgrading the cohort, never by copying configuration.
|
|
8
|
+
|
|
9
|
+
## What a workspace gets
|
|
10
|
+
|
|
11
|
+
`mpfrontend init` writes a root `eslint.config.mjs` and `prettier.config.mjs` that re-export this
|
|
12
|
+
profile, and `mpfrontend create app` writes an app `eslint.config.mjs` that spreads the root array and
|
|
13
|
+
a `tsconfig.json` that extends `@mpfrontend/workspace-config/tsconfig/next.json`. An app or a package adds
|
|
14
|
+
only its own additions after the shared part.
|
|
15
|
+
|
|
16
|
+
| Export | Contents |
|
|
17
|
+
|---|---|
|
|
18
|
+
| `@mpfrontend/workspace-config/eslint` | `workspaceConfig(options)`, `defaultDepConstraints`, `defaultThemeFiles`, `defaultGlobalStyleEntries`, `defaultIgnores` and the `plugin` with the rules below |
|
|
19
|
+
| `@mpfrontend/workspace-config/prettier` | The formatter profile: print width 100, single quotes, trailing commas, LF line endings |
|
|
20
|
+
| `@mpfrontend/workspace-config/tsconfig/base.json` | Strict TypeScript options shared by every project |
|
|
21
|
+
| `@mpfrontend/workspace-config/tsconfig/next.json` | The base plus the Next.js application options |
|
|
22
|
+
| `@mpfrontend/workspace-config/tsconfig/library.json` | The base plus the options of a shared package |
|
|
23
|
+
|
|
24
|
+
## Rules
|
|
25
|
+
|
|
26
|
+
| Rule | Fails on |
|
|
27
|
+
|---|---|
|
|
28
|
+
| `@nx/enforce-module-boundaries` | An import that crosses the tag constraints: an app importing another app, a shared package importing an app, a universal project importing a runtime-specific one |
|
|
29
|
+
| `mpfrontend/no-raw-color` | Hex values, `rgb()`, `rgba()`, `hsl()`, `hsla()` (and the other colour functions) and named colours in TS, TSX and CSS; Tailwind palette utilities such as `text-red-500`; Tailwind arbitrary colour values such as `bg-[#123456]` |
|
|
30
|
+
| `mpfrontend/no-handwritten-css` | Any CSS file outside the theme layer and the global entry; class and id rules, keyframes, font faces and `@theme` in the global entry; inline `style` objects other than CSS custom properties; `<style>` elements |
|
|
31
|
+
| `mpfrontend/logical-properties` | Physical left and right in TS, TSX and CSS: utilities such as `ml-2`, `pr-4`, `left-0`, `border-l`, `rounded-tr-md`, `text-right` and `float-left` (also behind variants), inline style keys such as `marginLeft`, CSS properties such as `margin-left`, `right` and `border-top-left-radius`, and `left` or `right` for `text-align`, `float` and `clear`. Logical forms (`ms-*`, `pe-*`, `start-*`, `border-s`, `text-end`, `margin-inline-start`) pass |
|
|
32
|
+
| `@typescript-eslint/no-explicit-any` | `any` in hand-written code |
|
|
33
|
+
|
|
34
|
+
CSS variables such as `var(--mp-surface-panel)`, `currentColor`, `transparent` and Tailwind arbitrary
|
|
35
|
+
values that are not colours (`w-[42rem]`, `grid-cols-[1fr_2fr]`) stay allowed. Generated contracts
|
|
36
|
+
(`**/generated/**`, `*.gen.ts`) and build output are not linted as hand-written code; `generated-check`
|
|
37
|
+
owns them.
|
|
38
|
+
|
|
39
|
+
## Configuration
|
|
40
|
+
|
|
41
|
+
The allowed paths are options, not edits to the profile:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import {defaultDepConstraints, workspaceConfig} from '@mpfrontend/workspace-config/eslint';
|
|
45
|
+
|
|
46
|
+
export default [
|
|
47
|
+
...workspaceConfig({
|
|
48
|
+
themeFiles: ['**/src/theme/**', '**/themes/**'],
|
|
49
|
+
globalStyleEntries: ['**/src/app/globals.css'],
|
|
50
|
+
depConstraints: [
|
|
51
|
+
...defaultDepConstraints,
|
|
52
|
+
{sourceTag: 'scope:billing', onlyDependOnLibsWithTags: ['scope:billing', 'scope:shared']},
|
|
53
|
+
],
|
|
54
|
+
allowedPhysical: [
|
|
55
|
+
{value: 'left-1/2', reason: 'Centred with -translate-x-1/2, which does not depend on the direction'},
|
|
56
|
+
],
|
|
57
|
+
}),
|
|
58
|
+
];
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`allowedPhysical` lists the physical values a workspace keeps, each with the reason it does not depend on
|
|
62
|
+
the text direction; an entry without a reason of at least ten characters is a configuration error. It is
|
|
63
|
+
empty by default, and the sources and templates of MP Frontend need no entry (a test lints them all).
|
|
64
|
+
|
|
65
|
+
The tags come from the generators: an app carries `type:app`, `scope:<app>` and `runtime:mixed`; a shared
|
|
66
|
+
package carries `type:package`, `scope:shared` and a `runtime:*` tag. A rule can be extended or switched
|
|
67
|
+
off by a later configuration object in the consumer, as with any flat configuration; this package never
|
|
68
|
+
weakens the rules of the MP Frontend repository itself.
|
|
69
|
+
|
|
70
|
+
## Limits
|
|
71
|
+
|
|
72
|
+
The colour rule reads string literals, template literals, style objects, SVG colour attributes and CSS
|
|
73
|
+
values. A colour computed at run time from numbers is not detected. A string such as `'#add'` outside a
|
|
74
|
+
reference attribute (`href`, `id`, `htmlFor`) is read as a colour; disable the rule for that line with a
|
|
75
|
+
reason. Module boundaries need the Nx project graph, so they run through the workspace `lint` targets.
|
|
76
|
+
|
|
77
|
+
## Text
|
|
78
|
+
|
|
79
|
+
`mpfrontend/no-literal-text` fails on literal user-visible text in JSX (text children, string children and
|
|
80
|
+
the attributes `alt`, `title`, `placeholder`, `aria-label`, `label`, `helper`, `caption` and the other
|
|
81
|
+
visible-text attributes), and on a translated message joined to other text or a value by `+`, a template
|
|
82
|
+
literal or adjacent JSX text and expressions. Text comes from catalog messages with named parameters. The
|
|
83
|
+
documented allowlist for strings that are not user-visible text is the `allowedText` option of
|
|
84
|
+
`workspaceConfig` (regular expressions); strings without letters, such as a separator, are always allowed.
|
|
85
|
+
The translator names default to `t` (`translators` option).
|
package/dist/colors.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw colour detection shared by the TypeScript and CSS forms of the colour rule.
|
|
3
|
+
* A raw colour is a literal value (hex, a colour function or a named colour) instead of a design token.
|
|
4
|
+
*/
|
|
5
|
+
/** The named colours of CSS Color Module Level 4. `transparent`, `currentcolor` and system colours are not raw. */
|
|
6
|
+
export declare const namedColors: ReadonlySet<string>;
|
|
7
|
+
/** Colour functions whose arguments are literal channel values. `var()` and `color-mix()` of tokens stay allowed. */
|
|
8
|
+
export declare const colorFunctions: ReadonlySet<string>;
|
|
9
|
+
export type ColorFinding = Readonly<{
|
|
10
|
+
value: string;
|
|
11
|
+
index: number;
|
|
12
|
+
}>;
|
|
13
|
+
/** Hex values and colour functions anywhere in a text. */
|
|
14
|
+
export declare function literalColors(text: string): ColorFinding[];
|
|
15
|
+
/** Named colours used as whole words of a CSS value. */
|
|
16
|
+
export declare function namedColorWords(value: string): ColorFinding[];
|
|
17
|
+
/** Tailwind palette utilities and arbitrary colour values such as `bg-[#123456]` in a class string. */
|
|
18
|
+
export declare function utilityColors(text: string): ColorFinding[];
|
|
19
|
+
/** CSS properties whose values hold colours; used to find named colours in TS style objects and CSS-in-strings. */
|
|
20
|
+
export declare const colorProperties: ReadonlySet<string>;
|
|
21
|
+
/** `backgroundColor` -> `background-color`. */
|
|
22
|
+
export declare function kebab(name: string): string;
|
|
23
|
+
/** Declarations written inside a string, for example `"color: red"` in a style string. */
|
|
24
|
+
export declare function declarationColors(text: string): ColorFinding[];
|
package/dist/colors.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw colour detection shared by the TypeScript and CSS forms of the colour rule.
|
|
3
|
+
* A raw colour is a literal value (hex, a colour function or a named colour) instead of a design token.
|
|
4
|
+
*/
|
|
5
|
+
/** The named colours of CSS Color Module Level 4. `transparent`, `currentcolor` and system colours are not raw. */
|
|
6
|
+
export const namedColors = new Set([
|
|
7
|
+
'aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue',
|
|
8
|
+
'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk',
|
|
9
|
+
'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki',
|
|
10
|
+
'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen',
|
|
11
|
+
'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue',
|
|
12
|
+
'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'fuchsia', 'gainsboro',
|
|
13
|
+
'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred',
|
|
14
|
+
'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral',
|
|
15
|
+
'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon',
|
|
16
|
+
'lightseagreen', 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'lime',
|
|
17
|
+
'limegreen', 'linen', 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple',
|
|
18
|
+
'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue',
|
|
19
|
+
'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'navy', 'oldlace', 'olive', 'olivedrab', 'orange',
|
|
20
|
+
'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff',
|
|
21
|
+
'peru', 'pink', 'plum', 'powderblue', 'purple', 'rebeccapurple', 'red', 'rosybrown', 'royalblue', 'saddlebrown',
|
|
22
|
+
'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue', 'slategray',
|
|
23
|
+
'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'teal', 'thistle', 'tomato', 'turquoise', 'violet',
|
|
24
|
+
'wheat', 'white', 'whitesmoke', 'yellow', 'yellowgreen',
|
|
25
|
+
]);
|
|
26
|
+
/** Colour functions whose arguments are literal channel values. `var()` and `color-mix()` of tokens stay allowed. */
|
|
27
|
+
export const colorFunctions = new Set([
|
|
28
|
+
'rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'lab', 'lch', 'oklab', 'oklch', 'color',
|
|
29
|
+
]);
|
|
30
|
+
const hexPattern = /(?:^|[^\w&/-])(#(?:[0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{3,4}))(?![\w-])/gi;
|
|
31
|
+
const functionPattern = /(?:^|[^\w-])((?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\()/gi;
|
|
32
|
+
const wordPattern = /[a-z]+/gi;
|
|
33
|
+
/** Tailwind's default palette names; a utility such as `bg-red-500` bypasses the design tokens. */
|
|
34
|
+
const palette = [
|
|
35
|
+
'slate', 'gray', 'zinc', 'neutral', 'stone', 'red', 'orange', 'amber', 'yellow', 'lime', 'green', 'emerald', 'teal',
|
|
36
|
+
'cyan', 'sky', 'blue', 'indigo', 'violet', 'purple', 'fuchsia', 'pink', 'rose', 'mauve', 'olive', 'mist', 'taupe',
|
|
37
|
+
];
|
|
38
|
+
const colorUtilities = [
|
|
39
|
+
'bg', 'text', 'border', 'border-[xytrblse]', 'ring', 'ring-offset', 'outline', 'fill', 'stroke', 'from', 'via', 'to',
|
|
40
|
+
'decoration', 'accent', 'caret', 'shadow', 'inset-shadow', 'inset-ring', 'divide', 'placeholder', 'drop-shadow',
|
|
41
|
+
'text-shadow',
|
|
42
|
+
].join('|');
|
|
43
|
+
const paletteUtility = new RegExp(`(?:^|[\\s"'\`:!])((?:${colorUtilities})-(?:(?:${palette.join('|')})-(?:50|[1-9]00|950)|black|white)(?:/\\d+)?)(?![\\w-])`, 'g');
|
|
44
|
+
const arbitraryValue = /(?:^|[\s"'`:!])([a-z][a-z-]*-\[([^\]\s]+)\])/g;
|
|
45
|
+
function push(findings, value, index) {
|
|
46
|
+
findings.push({ value, index });
|
|
47
|
+
}
|
|
48
|
+
/** Hex values and colour functions anywhere in a text. */
|
|
49
|
+
export function literalColors(text) {
|
|
50
|
+
const findings = [];
|
|
51
|
+
for (const match of text.matchAll(hexPattern))
|
|
52
|
+
push(findings, match[1], match.index + match[0].indexOf(match[1]));
|
|
53
|
+
for (const match of text.matchAll(functionPattern)) {
|
|
54
|
+
const name = match[1].slice(0, -1).toLowerCase();
|
|
55
|
+
if (colorFunctions.has(name))
|
|
56
|
+
push(findings, match[1], match.index + match[0].indexOf(match[1]));
|
|
57
|
+
}
|
|
58
|
+
return findings;
|
|
59
|
+
}
|
|
60
|
+
/** Named colours used as whole words of a CSS value. */
|
|
61
|
+
export function namedColorWords(value) {
|
|
62
|
+
const findings = [];
|
|
63
|
+
for (const match of value.matchAll(wordPattern)) {
|
|
64
|
+
const before = value[match.index - 1] ?? ' ', after = value[match.index + match[0].length] ?? ' ';
|
|
65
|
+
// A word inside an identifier, a custom property, a path or a file name is not a colour value.
|
|
66
|
+
if (/[\w\-./$]/.test(before) || /[\w\-./(]/.test(after))
|
|
67
|
+
continue;
|
|
68
|
+
if (namedColors.has(match[0].toLowerCase()))
|
|
69
|
+
push(findings, match[0], match.index);
|
|
70
|
+
}
|
|
71
|
+
return findings;
|
|
72
|
+
}
|
|
73
|
+
/** Tailwind palette utilities and arbitrary colour values such as `bg-[#123456]` in a class string. */
|
|
74
|
+
export function utilityColors(text) {
|
|
75
|
+
const findings = [];
|
|
76
|
+
for (const match of text.matchAll(paletteUtility))
|
|
77
|
+
push(findings, match[1], match.index + match[0].indexOf(match[1]));
|
|
78
|
+
for (const match of text.matchAll(arbitraryValue)) {
|
|
79
|
+
const inner = match[2].replace(/^color:/i, '');
|
|
80
|
+
const raw = inner.startsWith('#') || /^(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\(/i.test(inner) ||
|
|
81
|
+
namedColors.has(inner.toLowerCase());
|
|
82
|
+
if (raw)
|
|
83
|
+
push(findings, match[1], match.index + match[0].indexOf(match[1]));
|
|
84
|
+
}
|
|
85
|
+
return findings;
|
|
86
|
+
}
|
|
87
|
+
/** CSS properties whose values hold colours; used to find named colours in TS style objects and CSS-in-strings. */
|
|
88
|
+
export const colorProperties = new Set([
|
|
89
|
+
'color', 'background', 'background-color', 'border', 'border-color', 'border-top', 'border-right',
|
|
90
|
+
'border-bottom', 'border-left', 'border-block', 'border-inline', 'border-top-color', 'border-right-color',
|
|
91
|
+
'border-bottom-color', 'border-left-color', 'border-block-color', 'border-inline-color',
|
|
92
|
+
'border-block-start-color', 'border-block-end-color', 'border-inline-start-color', 'border-inline-end-color',
|
|
93
|
+
'outline', 'outline-color', 'fill', 'stroke', 'stop-color', 'flood-color', 'lighting-color', 'caret-color',
|
|
94
|
+
'accent-color', 'text-decoration', 'text-decoration-color', 'column-rule', 'column-rule-color', 'box-shadow',
|
|
95
|
+
'text-shadow', 'scrollbar-color',
|
|
96
|
+
]);
|
|
97
|
+
/** `backgroundColor` -> `background-color`. */
|
|
98
|
+
export function kebab(name) {
|
|
99
|
+
return name.replace(/[A-Z]/g, letter => '-' + letter.toLowerCase());
|
|
100
|
+
}
|
|
101
|
+
/** Declarations written inside a string, for example `"color: red"` in a style string. */
|
|
102
|
+
export function declarationColors(text) {
|
|
103
|
+
const findings = [];
|
|
104
|
+
for (const match of text.matchAll(/(?:^|[;{\s])([a-z-]+)\s*:\s*([^;}]*)/gi)) {
|
|
105
|
+
if (!colorProperties.has(match[1].toLowerCase()))
|
|
106
|
+
continue;
|
|
107
|
+
const start = match.index + match[0].length - match[2].length;
|
|
108
|
+
for (const finding of namedColorWords(match[2]))
|
|
109
|
+
push(findings, finding.value, start + finding.index);
|
|
110
|
+
}
|
|
111
|
+
return findings;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.js","sourceRoot":"","sources":["../src/colors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,mHAAmH;AACnH,MAAM,CAAC,MAAM,WAAW,GAAwB,IAAI,GAAG,CAAC;IACtD,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM;IAChH,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,EAAE,UAAU;IACjH,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW;IAC5G,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc;IACpG,eAAe,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa;IAC3G,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW;IACrG,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW;IAC7G,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW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ACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ESLint, Linter } from 'eslint';
|
|
2
|
+
import { type PhysicalAllowance } from './rules/logical-properties.js';
|
|
3
|
+
export { globalEntryAtRules } from './rules/no-handwritten-css.js';
|
|
4
|
+
export { visibleTextAttributes } from './rules/no-literal-text.js';
|
|
5
|
+
export type { PhysicalAllowance } from './rules/logical-properties.js';
|
|
6
|
+
/** One constraint of `@nx/enforce-module-boundaries`, keyed by the project tags the generators write. */
|
|
7
|
+
export type DepConstraint = Readonly<{
|
|
8
|
+
sourceTag: string;
|
|
9
|
+
onlyDependOnLibsWithTags?: readonly string[];
|
|
10
|
+
notDependOnLibsWithTags?: readonly string[];
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Boundaries over the tags that `mpfrontend create app` and the package generator write:
|
|
14
|
+
* `type:app` or `type:package`, `scope:<app>` or `scope:shared`, and a `runtime:*` tag.
|
|
15
|
+
* An app never depends on another app; a shared package never depends on an app.
|
|
16
|
+
*/
|
|
17
|
+
export declare const defaultDepConstraints: readonly DepConstraint[];
|
|
18
|
+
/** Token and theme files: the only files that may hold raw colour values and token CSS. */
|
|
19
|
+
export declare const defaultThemeFiles: readonly string[];
|
|
20
|
+
/** The one global style entry of an app: imports and base element rules only. */
|
|
21
|
+
export declare const defaultGlobalStyleEntries: readonly string[];
|
|
22
|
+
/** Build output, dependencies and generated contracts are never linted by hand-written rules. */
|
|
23
|
+
export declare const defaultIgnores: readonly string[];
|
|
24
|
+
export declare const codeFiles: readonly string[];
|
|
25
|
+
export declare const styleFiles: readonly string[];
|
|
26
|
+
export type WorkspaceConfigOptions = Readonly<{
|
|
27
|
+
/** Replaces the default constraints; spread `defaultDepConstraints` to extend them. */
|
|
28
|
+
depConstraints?: readonly DepConstraint[];
|
|
29
|
+
/** Replaces the default theme and token file globs. */
|
|
30
|
+
themeFiles?: readonly string[];
|
|
31
|
+
/** Replaces the default global style entry globs. */
|
|
32
|
+
globalStyleEntries?: readonly string[];
|
|
33
|
+
/** Added to the default ignores. */
|
|
34
|
+
ignores?: readonly string[];
|
|
35
|
+
/** Names of translator functions whose results must not be joined to other text; default `t`. */
|
|
36
|
+
translators?: readonly string[];
|
|
37
|
+
/** The documented allowlist of literal strings that are not user-visible text, as regular expressions. */
|
|
38
|
+
allowedText?: readonly string[];
|
|
39
|
+
/**
|
|
40
|
+
* Physical left or right values that are allowed, each with its reason: a utility (`left-1/2`), a CSS
|
|
41
|
+
* property (`margin-left`) or an inline style key (`marginLeft`). Empty by default.
|
|
42
|
+
*/
|
|
43
|
+
allowedPhysical?: readonly PhysicalAllowance[];
|
|
44
|
+
}>;
|
|
45
|
+
/** The MP Frontend rules, for consumers that compose their own configuration. */
|
|
46
|
+
export declare const plugin: ESLint.Plugin;
|
|
47
|
+
/**
|
|
48
|
+
* The shared ESLint flat configuration of an MP Frontend workspace. A workspace exports it from its root
|
|
49
|
+
* `eslint.config.mjs`; an app or a package spreads the root array and appends only its own additions.
|
|
50
|
+
*/
|
|
51
|
+
export declare function workspaceConfig(options?: WorkspaceConfigOptions): Linter.Config[];
|
|
52
|
+
export default workspaceConfig;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import css from '@eslint/css';
|
|
2
|
+
import nx from '@nx/eslint-plugin';
|
|
3
|
+
import tseslint from 'typescript-eslint';
|
|
4
|
+
import noHandwrittenCss from './rules/no-handwritten-css.js';
|
|
5
|
+
import noRawColor from './rules/no-raw-color.js';
|
|
6
|
+
import publicEntry from './rules/public-entry.js';
|
|
7
|
+
import noLiteralText from './rules/no-literal-text.js';
|
|
8
|
+
import logicalProperties, {} from './rules/logical-properties.js';
|
|
9
|
+
export { globalEntryAtRules } from './rules/no-handwritten-css.js';
|
|
10
|
+
export { visibleTextAttributes } from './rules/no-literal-text.js';
|
|
11
|
+
/**
|
|
12
|
+
* Boundaries over the tags that `mpfrontend create app` and the package generator write:
|
|
13
|
+
* `type:app` or `type:package`, `scope:<app>` or `scope:shared`, and a `runtime:*` tag.
|
|
14
|
+
* An app never depends on another app; a shared package never depends on an app.
|
|
15
|
+
*/
|
|
16
|
+
export const defaultDepConstraints = [
|
|
17
|
+
{ sourceTag: 'type:app', onlyDependOnLibsWithTags: ['type:package'] },
|
|
18
|
+
{ sourceTag: 'type:package', onlyDependOnLibsWithTags: ['type:package'] },
|
|
19
|
+
{ sourceTag: 'scope:shared', onlyDependOnLibsWithTags: ['scope:shared'] },
|
|
20
|
+
{ sourceTag: 'runtime:universal', onlyDependOnLibsWithTags: ['runtime:universal'] },
|
|
21
|
+
{ sourceTag: 'runtime:client', notDependOnLibsWithTags: ['runtime:server'] },
|
|
22
|
+
{ sourceTag: 'runtime:server', notDependOnLibsWithTags: ['runtime:client'] },
|
|
23
|
+
];
|
|
24
|
+
/** Token and theme files: the only files that may hold raw colour values and token CSS. */
|
|
25
|
+
export const defaultThemeFiles = ['**/src/theme/**', '**/themes/**'];
|
|
26
|
+
/** The one global style entry of an app: imports and base element rules only. */
|
|
27
|
+
export const defaultGlobalStyleEntries = ['**/src/app/globals.css'];
|
|
28
|
+
/** Build output, dependencies and generated contracts are never linted by hand-written rules. */
|
|
29
|
+
export const defaultIgnores = [
|
|
30
|
+
'**/node_modules/**', '**/dist/**', '**/.next/**', '**/.nx/**', '**/runtime-assets/**', '**/coverage/**',
|
|
31
|
+
'**/generated/**', '**/*.gen.ts', '**/next-env.d.ts',
|
|
32
|
+
];
|
|
33
|
+
export const codeFiles = ['**/*.{js,mjs,cjs,jsx,ts,mts,cts,tsx}'];
|
|
34
|
+
export const styleFiles = ['**/*.css'];
|
|
35
|
+
/** The MP Frontend rules, for consumers that compose their own configuration. */
|
|
36
|
+
export const plugin = {
|
|
37
|
+
meta: { name: '@mpfrontend/workspace-config' },
|
|
38
|
+
rules: { 'no-raw-color': noRawColor, 'no-handwritten-css': noHandwrittenCss, 'public-entry': publicEntry, 'no-literal-text': noLiteralText,
|
|
39
|
+
'logical-properties': logicalProperties },
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The shared ESLint flat configuration of an MP Frontend workspace. A workspace exports it from its root
|
|
43
|
+
* `eslint.config.mjs`; an app or a package spreads the root array and appends only its own additions.
|
|
44
|
+
*/
|
|
45
|
+
export function workspaceConfig(options = {}) {
|
|
46
|
+
const themeFiles = [...(options.themeFiles ?? defaultThemeFiles)];
|
|
47
|
+
const globalStyleEntries = [...(options.globalStyleEntries ?? defaultGlobalStyleEntries)];
|
|
48
|
+
const physical = ['error', { allow: (options.allowedPhysical ?? []).map(entry => ({ ...entry })) }];
|
|
49
|
+
const typescript = tseslint.configs.recommended
|
|
50
|
+
.map(config => ({ ...config, files: config.files ?? [...codeFiles] }));
|
|
51
|
+
return [
|
|
52
|
+
{ name: 'mpfrontend/ignores', ignores: [...defaultIgnores, ...(options.ignores ?? [])] },
|
|
53
|
+
...typescript,
|
|
54
|
+
{
|
|
55
|
+
name: 'mpfrontend/code',
|
|
56
|
+
files: [...codeFiles],
|
|
57
|
+
plugins: { '@nx': nx, mpfrontend: plugin },
|
|
58
|
+
rules: {
|
|
59
|
+
'@nx/enforce-module-boundaries': ['error', {
|
|
60
|
+
enforceBuildableLibDependency: true,
|
|
61
|
+
allow: [],
|
|
62
|
+
depConstraints: (options.depConstraints ?? defaultDepConstraints).map(constraint => ({ ...constraint })),
|
|
63
|
+
}],
|
|
64
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
65
|
+
// A leading underscore marks a parameter that a framework passes but the code does not read.
|
|
66
|
+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
67
|
+
'mpfrontend/no-raw-color': 'error',
|
|
68
|
+
'mpfrontend/no-handwritten-css': ['error', { inlineStyle: 'custom-properties' }],
|
|
69
|
+
'mpfrontend/public-entry': 'error',
|
|
70
|
+
'mpfrontend/no-literal-text': ['error', { translators: [...(options.translators ?? ['t'])], allow: [...(options.allowedText ?? [])] }],
|
|
71
|
+
'mpfrontend/logical-properties': physical,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
// Configuration files are tooling glue: an app configuration imports the workspace configuration.
|
|
76
|
+
name: 'mpfrontend/configuration-files',
|
|
77
|
+
files: ['**/*.config.{js,mjs,cjs,ts,mts}'],
|
|
78
|
+
rules: { '@nx/enforce-module-boundaries': 'off' },
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: 'mpfrontend/styles',
|
|
82
|
+
files: [...styleFiles],
|
|
83
|
+
language: 'css/css',
|
|
84
|
+
languageOptions: { tolerant: true },
|
|
85
|
+
plugins: { css: css, mpfrontend: plugin },
|
|
86
|
+
rules: {
|
|
87
|
+
'mpfrontend/no-raw-color': 'error',
|
|
88
|
+
'mpfrontend/no-handwritten-css': ['error', { css: 'forbid' }],
|
|
89
|
+
'mpfrontend/logical-properties': physical,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'mpfrontend/global-style-entry',
|
|
94
|
+
files: globalStyleEntries,
|
|
95
|
+
rules: { 'mpfrontend/no-handwritten-css': ['error', { css: 'global-entry' }] },
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'mpfrontend/theme-layer',
|
|
99
|
+
files: themeFiles,
|
|
100
|
+
rules: { 'mpfrontend/no-raw-color': 'off', 'mpfrontend/no-handwritten-css': 'off' },
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
export default workspaceConfig;
|
|
105
|
+
//# sourceMappingURL=eslint-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eslint-core.js","sourceRoot":"","sources":["../src/eslint-core.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,aAAa,CAAC;AAC9B,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACnC,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,gBAAgB,MAAM,+BAA+B,CA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EAAC;YACnE,KAAK,EAAE;gBACL,yBAAyB,EAAE,OAAO;gBAClC,+BAA+B,EAAE,CAAC,OAAO,EAAE,EAAC,GAAG,EAAE,QAAQ,EAAC,CAAC;gBAC3D,+BAA+B,EAAE,QAAQ;aAC1C;SACF;QACD;YACE,IAAI,EAAE,+BAA+B;YACrC,KAAK,EAAE,kBAAkB;YACzB,KAAK,EAAE,EAAC,+BAA+B,EAAE,CAAC,OAAO,EAAE,EAAC,GAAG,EAAE,cAAc,EAAC,CAAC,EAAC;SAC3E;QACD;YACE,IAAI,EAAE,wBAAwB;YAC9B,KAAK,EAAE,UAAU;YACjB,KAAK,EAAE,EAAC,yBAAyB,EAAE,KAAK,EAAE,+BAA+B,EAAE,KAAK,EAAC;SAClF;KACF,CAAC;AACJ,CAAC;AAED,eAAe,eAAe,CAAC"}
|
package/dist/eslint.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default, defaultDepConstraints, defaultGlobalStyleEntries, defaultIgnores, defaultThemeFiles, type DepConstraint, type PhysicalAllowance, plugin, workspaceConfig, type WorkspaceConfigOptions, } from './eslint-core.js';
|
package/dist/eslint.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eslint.js","sourceRoot":"","sources":["../src/eslint.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,qBAAqB,EACrB,yBAAyB,EACzB,cAAc,EACd,iBAAiB,EAGjB,MAAM,EACN,eAAe,GAEhB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { codeFiles, globalEntryAtRules, styleFiles, visibleTextAttributes } from './eslint-core.js';
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,OAAO,EAAC,SAAS,EAAC,kBAAkB,EAAC,UAAU,EAAC,qBAAqB,EAAC,MAAM,kBAAkB,CAAC"}
|