@mscode-pl/email-lint 0.0.0-stage → 0.1.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 +24 -0
- package/README.md +198 -3
- package/data/caniemail.json +1 -0
- package/dist/cli/colors.d.ts +13 -0
- package/dist/cli/colors.js +23 -0
- package/dist/cli/config.d.ts +11 -0
- package/dist/cli/config.js +56 -0
- package/dist/cli/files.d.ts +7 -0
- package/dist/cli/files.js +44 -0
- package/dist/cli/format.d.ts +23 -0
- package/dist/cli/format.js +204 -0
- package/dist/cli/interactive.d.ts +1 -0
- package/dist/cli/interactive.js +154 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +136 -0
- package/dist/core/baseline.d.ts +1 -0
- package/dist/core/baseline.js +24 -0
- package/dist/core/clients.d.ts +22 -0
- package/dist/core/clients.js +65 -0
- package/dist/core/data.d.ts +20 -0
- package/dist/core/data.js +6 -0
- package/dist/core/lint.d.ts +27 -0
- package/dist/core/lint.js +217 -0
- package/dist/core/rules.d.ts +23 -0
- package/dist/core/rules.js +164 -0
- package/dist/core/selectors.d.ts +15 -0
- package/dist/core/selectors.js +47 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +6 -0
- package/package.json +66 -6
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
2
|
+
const props = (...names) => (d) => names.includes(d.prop);
|
|
3
|
+
const propMatch = (re) => (d) => re.test(d.prop);
|
|
4
|
+
const valueMatch = (re) => (d) => re.test(d.value);
|
|
5
|
+
const declValue = (prop, re) => (d) => d.prop === prop && re.test(d.value);
|
|
6
|
+
const media = (re) => (a) => a.name === 'media' && re.test(a.params);
|
|
7
|
+
const tags = (...names) => (e) => names.includes(e.tag);
|
|
8
|
+
const hasAttr = (...names) => (e) => names.some((n) => n in e.attrs);
|
|
9
|
+
const inputType = (tag, type) => (e) => e.tag === tag && (e.attrs.type ?? '').toLowerCase() === type;
|
|
10
|
+
const hrefStarts = (prefix) => (e) => e.tag === 'a' && (e.attrs.href ?? '').trim().toLowerCase().startsWith(prefix);
|
|
11
|
+
const keyword = (words) => new RegExp(`(?<![\\w-])(${words})(?![\\w-])`, 'i');
|
|
12
|
+
const fn = (names) => new RegExp(`(?<![\\w-])(${names})\\(`, 'i');
|
|
13
|
+
const manual = {
|
|
14
|
+
'css-at-font-face': { atRule: (a) => a.name === 'font-face' },
|
|
15
|
+
'css-at-import': { atRule: (a) => a.name === 'import' },
|
|
16
|
+
'css-at-keyframes': { atRule: (a) => /^(-webkit-)?keyframes$/.test(a.name) },
|
|
17
|
+
'css-at-media': { atRule: (a) => a.name === 'media' },
|
|
18
|
+
'css-at-supports': { atRule: (a) => a.name === 'supports' },
|
|
19
|
+
'css-at-media-device-pixel-ratio': { atRule: media(/device-pixel-ratio/i) },
|
|
20
|
+
'css-at-media-hover': { atRule: media(/\((any-)?hover\b/i) },
|
|
21
|
+
'css-at-media-orientation': { atRule: media(/\borientation\b/i) },
|
|
22
|
+
'css-at-media-prefers-color-scheme': { atRule: media(/prefers-color-scheme/i) },
|
|
23
|
+
'css-at-media-prefers-reduced-motion': { atRule: media(/prefers-reduced-motion/i) },
|
|
24
|
+
'css-block-inline-size': { decl: props('block-size', 'inline-size') },
|
|
25
|
+
'css-inline-size': { decl: props('inline-size') },
|
|
26
|
+
'css-border-inline-block': { decl: props('border-inline', 'border-block') },
|
|
27
|
+
'css-border-inline-block-longhand': {
|
|
28
|
+
decl: propMatch(/^border-(inline|block)-(width|style|color)$/),
|
|
29
|
+
},
|
|
30
|
+
'css-border-inline-block-individual': {
|
|
31
|
+
decl: propMatch(/^border-(inline|block)-(start|end)(-(width|style|color))?$/),
|
|
32
|
+
},
|
|
33
|
+
'css-border-radius-logical': { decl: propMatch(/^border-(start|end)-(start|end)-radius$/) },
|
|
34
|
+
'css-color-scheme': { decl: props('color-scheme') },
|
|
35
|
+
'css-column-layout-properties': {
|
|
36
|
+
decl: propMatch(/^(columns|column-(width|span|fill|rule(-width|-style|-color)?))$/),
|
|
37
|
+
},
|
|
38
|
+
'css-display-flex': { decl: declValue('display', keyword('flex|inline-flex')) },
|
|
39
|
+
'css-display-grid': { decl: declValue('display', keyword('grid|inline-grid')) },
|
|
40
|
+
'css-display-none': { decl: declValue('display', keyword('none')) },
|
|
41
|
+
'css-flex-direction': { decl: props('flex-direction') },
|
|
42
|
+
'css-flex-wrap': { decl: declValue('flex-wrap', keyword('wrap|wrap-reverse')) },
|
|
43
|
+
'css-font': { decl: props('font') },
|
|
44
|
+
'css-gap': { decl: props('gap', 'column-gap', 'row-gap', 'grid-gap') },
|
|
45
|
+
'css-grid-template': { decl: propMatch(/^grid-template/) },
|
|
46
|
+
'css-important': { decl: (d) => d.important },
|
|
47
|
+
'css-intrinsic-size': { decl: valueMatch(keyword('fit-content|min-content|max-content')) },
|
|
48
|
+
'css-left-right-top-bottom': { decl: props('left', 'right', 'top', 'bottom') },
|
|
49
|
+
'css-margin-block-start-end': { decl: props('margin-block-start', 'margin-block-end') },
|
|
50
|
+
'css-margin-inline-block': { decl: props('margin-inline', 'margin-block') },
|
|
51
|
+
'css-margin-inline-start-end': { decl: props('margin-inline-start', 'margin-inline-end') },
|
|
52
|
+
'css-padding-block-start-end': { decl: props('padding-block-start', 'padding-block-end') },
|
|
53
|
+
'css-padding-inline-block': { decl: props('padding-inline', 'padding-block') },
|
|
54
|
+
'css-padding-inline-start-end': {
|
|
55
|
+
decl: props('padding-inline-start', 'padding-inline-end'),
|
|
56
|
+
},
|
|
57
|
+
'css-modern-color': { decl: valueMatch(fn('lch|oklch|lab|oklab')) },
|
|
58
|
+
'css-sytem-ui': {
|
|
59
|
+
decl: valueMatch(keyword('system-ui|ui-serif|ui-sans-serif|ui-rounded|ui-monospace')),
|
|
60
|
+
},
|
|
61
|
+
'css-unit-calc': { decl: valueMatch(fn('calc')) },
|
|
62
|
+
'css-variables': { decl: (d) => d.prop.startsWith('--') || fn('var').test(d.value) },
|
|
63
|
+
'css-unit-initial': { decl: valueMatch(keyword('initial')) },
|
|
64
|
+
'css-selector-grouping': { selector: (s) => s.grouping },
|
|
65
|
+
'css-selector-child': { selector: (s) => s.child },
|
|
66
|
+
'css-selector-adjacent-sibling': { selector: (s) => s.adjacent },
|
|
67
|
+
'css-selector-general-sibling': { selector: (s) => s.generalSibling },
|
|
68
|
+
'css-selector-descendant': { selector: (s) => s.descendant },
|
|
69
|
+
'css-selector-type': { selector: (s) => s.type },
|
|
70
|
+
'css-selector-universal': { selector: (s) => s.universal },
|
|
71
|
+
'css-selector-class': { selector: (s) => s.cls },
|
|
72
|
+
'css-selector-id': { selector: (s) => s.id },
|
|
73
|
+
'css-selector-attribute': { selector: (s) => s.attribute },
|
|
74
|
+
'css-selector-chaining': { selector: (s) => s.chaining },
|
|
75
|
+
'html-address': { element: tags('address') },
|
|
76
|
+
'html-base': { element: tags('base') },
|
|
77
|
+
'html-h1-h6': { element: tags('h1', 'h2', 'h3', 'h4', 'h5', 'h6') },
|
|
78
|
+
'html-lists': { element: tags('ul', 'ol', 'dl') },
|
|
79
|
+
'html-svg': { element: tags('svg') },
|
|
80
|
+
'html-semantics': {
|
|
81
|
+
element: tags('article', 'aside', 'details', 'figcaption', 'figure', 'footer', 'header', 'main', 'mark', 'nav', 'section', 'summary', 'time'),
|
|
82
|
+
},
|
|
83
|
+
'html-image-maps': { element: (e) => e.tag === 'map' || 'usemap' in e.attrs },
|
|
84
|
+
'html-anchor-links': { element: hrefStarts('#') },
|
|
85
|
+
'html-mailto-links': { element: hrefStarts('mailto:') },
|
|
86
|
+
'html-meta-color-scheme': {
|
|
87
|
+
element: (e) => e.tag === 'meta' && /^(color-scheme|supported-color-schemes)$/i.test(e.attrs.name ?? ''),
|
|
88
|
+
},
|
|
89
|
+
'html-srcset': { element: hasAttr('srcset', 'sizes') },
|
|
90
|
+
'html-command-attribute': { element: hasAttr('command', 'commandfor') },
|
|
91
|
+
'html-button-reset': { element: inputType('button', 'reset') },
|
|
92
|
+
'html-button-submit': { element: inputType('button', 'submit') },
|
|
93
|
+
'html-input-checkbox': { element: inputType('input', 'checkbox') },
|
|
94
|
+
'html-input-hidden': { element: inputType('input', 'hidden') },
|
|
95
|
+
'html-input-radio': { element: inputType('input', 'radio') },
|
|
96
|
+
'html-input-reset': { element: inputType('input', 'reset') },
|
|
97
|
+
'html-input-submit': { element: inputType('input', 'submit') },
|
|
98
|
+
'html-input-text': { element: inputType('input', 'text') },
|
|
99
|
+
amp: { element: (e) => e.tag === 'html' && ('⚡4email' in e.attrs || 'amp4email' in e.attrs) },
|
|
100
|
+
};
|
|
101
|
+
const UNIT_PREFIX = String.raw `(?<![\w#.-])-?(?:\d+\.?\d*|\.\d+)`;
|
|
102
|
+
function autoRule(feature) {
|
|
103
|
+
const title = feature.title.trim();
|
|
104
|
+
if (feature.category === 'css') {
|
|
105
|
+
let m;
|
|
106
|
+
if ((m = title.match(/^([a-z-]+)(?: property)?$/))) {
|
|
107
|
+
if (m[1] === 'inert')
|
|
108
|
+
return { element: hasAttr('inert') };
|
|
109
|
+
return { decl: props(m[1]) };
|
|
110
|
+
}
|
|
111
|
+
if ((m = title.match(/^(::?)([a-z-]+)(\(\))?$/))) {
|
|
112
|
+
const name = escape(m[2]) + (m[3] ? String.raw `\(` : '(?![\\w-])');
|
|
113
|
+
// `::before` also has a legacy single-colon form.
|
|
114
|
+
const re = m[1] === '::' ? new RegExp(`::?${name}`) : new RegExp(`(?<!:):${name}`);
|
|
115
|
+
return { selector: (s) => re.test(s.raw) };
|
|
116
|
+
}
|
|
117
|
+
if (title === 'lang()') {
|
|
118
|
+
return { selector: (s) => /:lang\(/.test(s.raw) };
|
|
119
|
+
}
|
|
120
|
+
if ((m = title.match(/^([a-z-]+)\(\)$/))) {
|
|
121
|
+
return { decl: valueMatch(fn(escape(m[1]))) };
|
|
122
|
+
}
|
|
123
|
+
if ((m = title.match(/^([a-z%]+) unit$/))) {
|
|
124
|
+
const re = new RegExp(`${UNIT_PREFIX}${escape(m[1])}${m[1] === '%' ? '' : '(?![\\w-])'}`, 'i');
|
|
125
|
+
return { decl: valueMatch(re) };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (feature.category === 'html') {
|
|
129
|
+
let m;
|
|
130
|
+
if ((m = title.match(/^<([a-z0-9]+)> element$/)))
|
|
131
|
+
return { element: tags(m[1]) };
|
|
132
|
+
if ((m = title.match(/^([a-z-]+) attribute$/)))
|
|
133
|
+
return { element: hasAttr(m[1]) };
|
|
134
|
+
}
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
export function buildRules(features) {
|
|
138
|
+
const rules = new Map();
|
|
139
|
+
for (const feature of features) {
|
|
140
|
+
const rule = manual[feature.slug] ?? autoRule(feature);
|
|
141
|
+
if (rule)
|
|
142
|
+
rules.set(feature.slug, rule);
|
|
143
|
+
}
|
|
144
|
+
return rules;
|
|
145
|
+
}
|
|
146
|
+
export const DOCUMENT_FEATURES = new Set([
|
|
147
|
+
'css-comments',
|
|
148
|
+
'css-nesting',
|
|
149
|
+
'html-comments',
|
|
150
|
+
'html-doctype',
|
|
151
|
+
'image-apng',
|
|
152
|
+
'image-avif',
|
|
153
|
+
'image-base64',
|
|
154
|
+
'image-bmp',
|
|
155
|
+
'image-gif',
|
|
156
|
+
'image-heif',
|
|
157
|
+
'image-ico',
|
|
158
|
+
'image-jpg',
|
|
159
|
+
'image-mp4',
|
|
160
|
+
'image-png',
|
|
161
|
+
'image-svg',
|
|
162
|
+
'image-tiff',
|
|
163
|
+
'image-webp',
|
|
164
|
+
]);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface SelectorInfo {
|
|
2
|
+
raw: string;
|
|
3
|
+
grouping: boolean;
|
|
4
|
+
child: boolean;
|
|
5
|
+
adjacent: boolean;
|
|
6
|
+
generalSibling: boolean;
|
|
7
|
+
descendant: boolean;
|
|
8
|
+
type: boolean;
|
|
9
|
+
universal: boolean;
|
|
10
|
+
cls: boolean;
|
|
11
|
+
id: boolean;
|
|
12
|
+
attribute: boolean;
|
|
13
|
+
chaining: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function analyzeSelector(selector: string): SelectorInfo;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export function analyzeSelector(selector) {
|
|
2
|
+
let s = selector.replace(/"[^"]*"|'[^']*'/g, '""').replace(/\[[^\]]*\]/g, '[]');
|
|
3
|
+
// Collapse pseudo-class arguments so `:not(.a > b)` does not count as a child combinator.
|
|
4
|
+
while (/\([^()]+\)/.test(s))
|
|
5
|
+
s = s.replace(/\([^()]+\)/g, '()');
|
|
6
|
+
const parts = s.split(',').map((p) => p.trim()).filter(Boolean);
|
|
7
|
+
const info = {
|
|
8
|
+
raw: selector,
|
|
9
|
+
grouping: parts.length > 1,
|
|
10
|
+
child: false,
|
|
11
|
+
adjacent: false,
|
|
12
|
+
generalSibling: false,
|
|
13
|
+
descendant: false,
|
|
14
|
+
type: false,
|
|
15
|
+
universal: false,
|
|
16
|
+
cls: false,
|
|
17
|
+
id: false,
|
|
18
|
+
attribute: false,
|
|
19
|
+
chaining: false,
|
|
20
|
+
};
|
|
21
|
+
for (const part of parts) {
|
|
22
|
+
const tight = part.replace(/\s*([>+~])\s*/g, '$1');
|
|
23
|
+
if (tight.includes('>'))
|
|
24
|
+
info.child = true;
|
|
25
|
+
if (tight.includes('+'))
|
|
26
|
+
info.adjacent = true;
|
|
27
|
+
if (tight.includes('~'))
|
|
28
|
+
info.generalSibling = true;
|
|
29
|
+
if (/\S\s+\S/.test(tight))
|
|
30
|
+
info.descendant = true;
|
|
31
|
+
for (const compound of tight.split(/[\s>+~]+/)) {
|
|
32
|
+
if (/^[a-z][\w-]*/i.test(compound))
|
|
33
|
+
info.type = true;
|
|
34
|
+
if (compound.startsWith('*'))
|
|
35
|
+
info.universal = true;
|
|
36
|
+
if (/\.[\w-]/.test(compound))
|
|
37
|
+
info.cls = true;
|
|
38
|
+
if (/#[\w-]/.test(compound))
|
|
39
|
+
info.id = true;
|
|
40
|
+
if (compound.includes('[]'))
|
|
41
|
+
info.attribute = true;
|
|
42
|
+
if ((compound.match(/\.[\w-]+|#[\w-]+|\[\]/g) ?? []).length >= 2)
|
|
43
|
+
info.chaining = true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return info;
|
|
47
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { lint } from './core/lint.js';
|
|
2
|
+
export type { LintOptions, LintResult, Issue, ParseError } from './core/lint.js';
|
|
3
|
+
export { analyzeSelector } from './core/selectors.js';
|
|
4
|
+
export type { SelectorInfo } from './core/selectors.js';
|
|
5
|
+
export { BASELINE_FEATURES } from './core/baseline.js';
|
|
6
|
+
export { DEFAULT_CLIENTS, SKIPPED_PLATFORMS } from './core/clients.js';
|
|
7
|
+
export type { ClientSupport, Status } from './core/clients.js';
|
|
8
|
+
export { loadDataset } from './core/data.js';
|
|
9
|
+
export type { Dataset, Feature } from './core/data.js';
|
|
10
|
+
export { formatText, formatMarkdown, formatGithub } from './cli/format.js';
|
|
11
|
+
export type { FileResult, Format } from './cli/format.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { lint } from './core/lint.js';
|
|
2
|
+
export { analyzeSelector } from './core/selectors.js';
|
|
3
|
+
export { BASELINE_FEATURES } from './core/baseline.js';
|
|
4
|
+
export { DEFAULT_CLIENTS, SKIPPED_PLATFORMS } from './core/clients.js';
|
|
5
|
+
export { loadDataset } from './core/data.js';
|
|
6
|
+
export { formatText, formatMarkdown, formatGithub } from './cli/format.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,66 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@mscode-pl/email-lint",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@mscode-pl/email-lint",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Find the CSS and HTML in your emails that Outlook, Gmail, Apple Mail and other clients will break, with line numbers. Works with React Email, MJML, Maizzle, Laravel and plain HTML.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "MSCode (https://mscode.pl)",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"homepage": "https://github.com/mscode-pl/email-lint#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/mscode-pl/email-lint.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/mscode-pl/email-lint/issues",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"email",
|
|
16
|
+
"html-email",
|
|
17
|
+
"lint",
|
|
18
|
+
"linter",
|
|
19
|
+
"caniemail",
|
|
20
|
+
"outlook",
|
|
21
|
+
"gmail",
|
|
22
|
+
"react-email",
|
|
23
|
+
"mjml",
|
|
24
|
+
"maizzle",
|
|
25
|
+
"cli"
|
|
26
|
+
],
|
|
27
|
+
"bin": {
|
|
28
|
+
"email-lint": "dist/cli/main.js"
|
|
29
|
+
},
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"data"
|
|
39
|
+
],
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=22"
|
|
42
|
+
},
|
|
43
|
+
"packageManager": "pnpm@12.14.0",
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc -p tsconfig.build.json",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"test": "vitest run",
|
|
51
|
+
"update-data": "node scripts/update-data.mjs",
|
|
52
|
+
"screenshot": "pnpm build && node scripts/render-screenshot.mjs",
|
|
53
|
+
"prepublishOnly": "pnpm typecheck && pnpm test && pnpm build"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@clack/prompts": "^1.9.0",
|
|
57
|
+
"domhandler": "^6.0.1",
|
|
58
|
+
"htmlparser2": "^12.0.0",
|
|
59
|
+
"postcss": "^8.5.33"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@types/node": "^24.19.4",
|
|
63
|
+
"typescript": "^5.9.3",
|
|
64
|
+
"vitest": "^5.1.2"
|
|
65
|
+
}
|
|
66
|
+
}
|