-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.ts
More file actions
77 lines (75 loc) · 1.72 KB
/
plugin.ts
File metadata and controls
77 lines (75 loc) · 1.72 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
/**
* Deno lint plugin to prevent inline styles in JSX/TSX components.
*
* This rule blocks all usage of the `style` prop on JSX elements to enforce
* consistent styling through CSS classes (Tailwind, CSS modules, etc.).
*
* ## Installation
*
* Add the plugin to your `deno.json`:
*
* ```json
* {
* "lint": {
* "plugins": ["jsr:@intility/no-inline-styles"],
* "rules": {
* "tags": ["recommended"],
* "include": ["no-inline-styles/no-inline-styles"]
* }
* }
* }
* ```
*
* ## Usage
*
* Once configured, the plugin will flag any inline styles:
*
* ```tsx
* // ❌ Error: Inline styles are not allowed
* <div style={{ color: 'red', padding: '10px' }}>
* Content
* </div>
*
* // ✅ Good: Use CSS classes
* <div className="text-red-500 p-2">
* Content
* </div>
* ```
*
* ## Ignoring Specific Cases
*
* If you have legitimate use cases for inline styles, you can ignore specific lines:
*
* ```tsx
* // deno-lint-ignore no-inline-styles/no-inline-styles
* <div style={{ backgroundColor: dynamicColor }}>
* Content
* </div>
* ```
*
* @module
*/
/**
* Deno lint plugin that enforces CSS classes over inline styles in JSX/TSX.
*
* Provides a single rule that detects and reports any usage of the `style` prop on JSX elements.
*/
const plugin: Deno.lint.Plugin = {
name: "no-inline-styles",
rules: {
"no-inline-styles": {
create(context) {
return {
'JSXAttribute[name.name="style"]'(node) {
context.report({
node,
message:
"Inline styles are not allowed. Use CSS classes (Tailwind, CSS modules, etc.) instead.",
});
},
};
},
},
},
};
export default plugin;