-
-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathlint.ts
More file actions
107 lines (95 loc) · 2.68 KB
/
lint.ts
File metadata and controls
107 lines (95 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { pluginNames } from "./core/utils/lume_config.ts";
// Check only the following plugins
const orderMatter = new Set([
"esbuild",
"terser",
"katex",
"google_fonts",
"sass",
"unocss",
"postcss",
"tailwindcss",
"lightningcss",
"purgecss",
"source_maps",
"slugify_urls",
"picture",
"transform_images",
"inline",
"base_path",
"feed",
"metas",
"og_images",
]);
const validOrder = pluginNames
.filter((name) => orderMatter.has(name))
.map((name) => `lume/plugins/${name}.ts`);
export default {
name: "lume",
rules: {
"plugin-order": {
create(context) {
const { filename } = context;
const files = ["_config.ts", "_config.js", "plugins.ts", "plugins.js"];
// Ignore files that are not lume config files
if (files.every((file) => !filename.endsWith(file))) {
return {};
}
const imports = new Map<string, number>();
const calls: string[] = [];
return {
"ImportDeclaration[source.value=/lume\/plugins\//]"(node) {
const source = node.source.value;
const identifier = node.specifiers[0].local.name;
const position = validOrder.indexOf(source);
if (position !== -1) {
imports.set(identifier, position);
}
},
CallExpression(node) {
const name = "name" in node.callee ? node.callee.name : undefined;
if (!name) {
return;
}
const position = imports.get(name);
if (position === undefined) {
return;
}
let validPrevious: [string, number] | undefined;
for (const callName of calls) {
const callPosition = imports.get(callName)!;
if (position < callPosition) {
if (!validPrevious || callPosition < validPrevious[1]) {
validPrevious = [callName, callPosition];
}
}
}
if (validPrevious) {
context.report({
node,
message:
`Invalid order of plugins: "${name}" should be used before "${
validPrevious[0]
}"`,
});
}
calls.push(name);
},
};
},
},
"jsx-spread-position": {
create(context) {
return {
"JSXSpreadAttribute:not(:last-child)"(node) {
context.report({
node,
message:
"JSX spread attributes should be at the end of the props",
});
},
};
},
},
},
} satisfies Deno.lint.Plugin;