@friendsoftheweb/eslint-plugin 0.0.1 → 0.0.2

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.
@@ -1,215 +0,0 @@
1
- 'use strict';
2
-
3
- var path = require('node:path');
4
- var fs = require('node:fs');
5
- var postcss = require('postcss');
6
- var selectorParser = require('postcss-selector-parser');
7
-
8
- /** @type {import('eslint').JSRuleDefinition} */
9
- var cssModuleClassExistsRule = {
10
- meta: {
11
- type: 'problem',
12
- docs: {
13
- description:
14
- 'enforce that class names used from an imported CSS module exist in the module file',
15
- },
16
- schema: [],
17
- messages: {
18
- relativePath:
19
- 'CSS module import "{{importPath}}" should be a relative path',
20
- defaultImport:
21
- 'CSS module import "{{importPath}}" should have a default import',
22
- onlyDefaultImport:
23
- 'CSS module import "{{importPath}}" should have only a default import',
24
- fileDoesNotExist:
25
- 'CSS module file "{{absoluteImportPath}}" does not exist',
26
- classDoesNotExist:
27
- 'Class `.{{className}}` does not exist in the CSS module imported as `{{objectName}}`',
28
- },
29
- },
30
- create(context) {
31
- const classNames = {};
32
-
33
- return {
34
- ImportDeclaration(node) {
35
- if (
36
- typeof node.source.value !== 'string' ||
37
- !node.source.value.endsWith('.module.css')
38
- ) {
39
- return;
40
- }
41
-
42
- const importPath = node.source.value;
43
-
44
- if (!(importPath.startsWith('./') || importPath.startsWith('../'))) {
45
- context.report({
46
- node,
47
- messageId: 'relativePath',
48
- data: { importPath },
49
- });
50
-
51
- return;
52
- }
53
-
54
- if (node.specifiers.length === 0) {
55
- context.report({
56
- node,
57
- messageId: 'defaultImport',
58
- data: { importPath },
59
- });
60
-
61
- return;
62
- }
63
-
64
- if (node.specifiers.length > 1) {
65
- context.report({
66
- node,
67
- messageId: 'onlyDefaultImport',
68
- data: { importPath },
69
- });
70
-
71
- return;
72
- }
73
-
74
- const defaultImportSpecifier = node.specifiers.find(
75
- (specifier) => specifier.type === 'ImportDefaultSpecifier',
76
- );
77
-
78
- if (defaultImportSpecifier == null) {
79
- context.report({
80
- node,
81
- messageId: 'onlyDefaultImport',
82
- data: { importPath },
83
- });
84
-
85
- return;
86
- }
87
-
88
- const dirname = path.dirname(context.physicalFilename);
89
- const absoluteImportPath = path.resolve(dirname, importPath);
90
-
91
- if (!fs.existsSync(absoluteImportPath)) {
92
- context.report({
93
- node,
94
- messageId: 'fileDoesNotExist',
95
- data: { absoluteImportPath },
96
- });
97
-
98
- return;
99
- }
100
-
101
- const importName = defaultImportSpecifier.local.name;
102
-
103
- classNames[importName] = new Set();
104
-
105
- const cssModuleContent = fs.readFileSync(absoluteImportPath, 'utf8');
106
- const root = postcss.parse(cssModuleContent);
107
-
108
- for (const node of root.nodes) {
109
- if (node.type === 'rule') {
110
- selectorParser(function transform(selectors) {
111
- selectors.walkClasses((classNode) => {
112
- classNames[importName].add(classNode.value);
113
- });
114
- }).processSync(node.selector);
115
- } else if (
116
- node.type === 'atrule' &&
117
- (node.name === 'media' ||
118
- node.name === 'container' ||
119
- node.name === 'layer')
120
- ) {
121
- for (const childNode of node.nodes) {
122
- if (childNode.type !== 'rule') {
123
- continue;
124
- }
125
-
126
- selectorParser(function transform(selectors) {
127
- selectors.walkClasses((classNode) => {
128
- classNames[importName].add(classNode.value);
129
- });
130
- }).processSync(childNode.selector);
131
- }
132
- }
133
- }
134
- },
135
- MemberExpression(node) {
136
- if (node.object.type !== 'Identifier') {
137
- return;
138
- }
139
-
140
- if (classNames[node.object.name] == null) {
141
- return;
142
- }
143
-
144
- const objectName = node.object.name;
145
-
146
- if (node.property.type === 'Identifier') {
147
- const className = node.property.name;
148
-
149
- if (!classNames[objectName].has(className)) {
150
- context.report({
151
- node,
152
- messageId: 'classDoesNotExist',
153
- data: { className, objectName },
154
- });
155
- }
156
-
157
- return;
158
- }
159
-
160
- if (
161
- node.property.type === 'Literal' &&
162
- typeof node.property.value === 'string'
163
- ) {
164
- const className = node.property.value;
165
-
166
- if (!classNames[objectName].has(className)) {
167
- context.report({
168
- node,
169
- messageId: 'classDoesNotExist',
170
- data: { className, objectName },
171
- });
172
- }
173
- }
174
- },
175
- VariableDeclarator(node) {
176
- if (node.id.type !== 'ObjectPattern') {
177
- return;
178
- }
179
-
180
- if (node.init?.type !== 'Identifier') {
181
- return;
182
- }
183
-
184
- const objectName = node.init.name;
185
-
186
- if (classNames[objectName] == null) {
187
- return;
188
- }
189
-
190
- for (const property of node.id.properties) {
191
- if (property.type !== 'Property') {
192
- continue;
193
- }
194
-
195
- if (property.key.type !== 'Identifier') {
196
- continue;
197
- }
198
-
199
- const className = property.key.name;
200
-
201
- if (!classNames[objectName].has(className)) {
202
- context.report({
203
- node: property,
204
- messageId: 'classDoesNotExist',
205
- data: { className, objectName },
206
- });
207
- }
208
- }
209
- },
210
- };
211
- },
212
- };
213
-
214
- module.exports = cssModuleClassExistsRule;
215
- //# sourceMappingURL=css-module-class-exists.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"css-module-class-exists.js","sources":["../../../src/rules/css-module-class-exists.mjs"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs';\n\nimport { parse } from 'postcss';\nimport selectorParser from 'postcss-selector-parser';\n\n/** @type {import('eslint').JSRuleDefinition} */\nexport default {\n meta: {\n type: 'problem',\n docs: {\n description:\n 'enforce that class names used from an imported CSS module exist in the module file',\n },\n schema: [],\n messages: {\n relativePath:\n 'CSS module import \"{{importPath}}\" should be a relative path',\n defaultImport:\n 'CSS module import \"{{importPath}}\" should have a default import',\n onlyDefaultImport:\n 'CSS module import \"{{importPath}}\" should have only a default import',\n fileDoesNotExist:\n 'CSS module file \"{{absoluteImportPath}}\" does not exist',\n classDoesNotExist:\n 'Class `.{{className}}` does not exist in the CSS module imported as `{{objectName}}`',\n },\n },\n create(context) {\n const classNames = {};\n\n return {\n ImportDeclaration(node) {\n if (\n typeof node.source.value !== 'string' ||\n !node.source.value.endsWith('.module.css')\n ) {\n return;\n }\n\n const importPath = node.source.value;\n\n if (!(importPath.startsWith('./') || importPath.startsWith('../'))) {\n context.report({\n node,\n messageId: 'relativePath',\n data: { importPath },\n });\n\n return;\n }\n\n if (node.specifiers.length === 0) {\n context.report({\n node,\n messageId: 'defaultImport',\n data: { importPath },\n });\n\n return;\n }\n\n if (node.specifiers.length > 1) {\n context.report({\n node,\n messageId: 'onlyDefaultImport',\n data: { importPath },\n });\n\n return;\n }\n\n const defaultImportSpecifier = node.specifiers.find(\n (specifier) => specifier.type === 'ImportDefaultSpecifier',\n );\n\n if (defaultImportSpecifier == null) {\n context.report({\n node,\n messageId: 'onlyDefaultImport',\n data: { importPath },\n });\n\n return;\n }\n\n const dirname = path.dirname(context.physicalFilename);\n const absoluteImportPath = path.resolve(dirname, importPath);\n\n if (!fs.existsSync(absoluteImportPath)) {\n context.report({\n node,\n messageId: 'fileDoesNotExist',\n data: { absoluteImportPath },\n });\n\n return;\n }\n\n const importName = defaultImportSpecifier.local.name;\n\n classNames[importName] = new Set();\n\n const cssModuleContent = fs.readFileSync(absoluteImportPath, 'utf8');\n const root = parse(cssModuleContent);\n\n for (const node of root.nodes) {\n if (node.type === 'rule') {\n selectorParser(function transform(selectors) {\n selectors.walkClasses((classNode) => {\n classNames[importName].add(classNode.value);\n });\n }).processSync(node.selector);\n } else if (\n node.type === 'atrule' &&\n (node.name === 'media' ||\n node.name === 'container' ||\n node.name === 'layer')\n ) {\n for (const childNode of node.nodes) {\n if (childNode.type !== 'rule') {\n continue;\n }\n\n selectorParser(function transform(selectors) {\n selectors.walkClasses((classNode) => {\n classNames[importName].add(classNode.value);\n });\n }).processSync(childNode.selector);\n }\n }\n }\n },\n MemberExpression(node) {\n if (node.object.type !== 'Identifier') {\n return;\n }\n\n if (classNames[node.object.name] == null) {\n return;\n }\n\n const objectName = node.object.name;\n\n if (node.property.type === 'Identifier') {\n const className = node.property.name;\n\n if (!classNames[objectName].has(className)) {\n context.report({\n node,\n messageId: 'classDoesNotExist',\n data: { className, objectName },\n });\n }\n\n return;\n }\n\n if (\n node.property.type === 'Literal' &&\n typeof node.property.value === 'string'\n ) {\n const className = node.property.value;\n\n if (!classNames[objectName].has(className)) {\n context.report({\n node,\n messageId: 'classDoesNotExist',\n data: { className, objectName },\n });\n }\n }\n },\n VariableDeclarator(node) {\n if (node.id.type !== 'ObjectPattern') {\n return;\n }\n\n if (node.init?.type !== 'Identifier') {\n return;\n }\n\n const objectName = node.init.name;\n\n if (classNames[objectName] == null) {\n return;\n }\n\n for (const property of node.id.properties) {\n if (property.type !== 'Property') {\n continue;\n }\n\n if (property.key.type !== 'Identifier') {\n continue;\n }\n\n const className = property.key.name;\n\n if (!classNames[objectName].has(className)) {\n context.report({\n node: property,\n messageId: 'classDoesNotExist',\n data: { className, objectName },\n });\n }\n }\n },\n };\n },\n};\n"],"names":["parse"],"mappings":";;;;;;;AAMA;AACA,+BAAe;AACf,EAAE,IAAI,EAAE;AACR,IAAI,IAAI,EAAE,SAAS;AACnB,IAAI,IAAI,EAAE;AACV,MAAM,WAAW;AACjB,QAAQ,oFAAoF;AAC5F,KAAK;AACL,IAAI,MAAM,EAAE,EAAE;AACd,IAAI,QAAQ,EAAE;AACd,MAAM,YAAY;AAClB,QAAQ,8DAA8D;AACtE,MAAM,aAAa;AACnB,QAAQ,iEAAiE;AACzE,MAAM,iBAAiB;AACvB,QAAQ,sEAAsE;AAC9E,MAAM,gBAAgB;AACtB,QAAQ,yDAAyD;AACjE,MAAM,iBAAiB;AACvB,QAAQ,sFAAsF;AAC9F,KAAK;AACL,GAAG;AACH,EAAE,MAAM,CAAC,OAAO,EAAE;AAClB,IAAI,MAAM,UAAU,GAAG,EAAE;;AAEzB,IAAI,OAAO;AACX,MAAM,iBAAiB,CAAC,IAAI,EAAE;AAC9B,QAAQ;AACR,UAAU,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,QAAQ;AAC/C,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa;AACnD,UAAU;AACV,UAAU;AACV;;AAEA,QAAQ,MAAM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Aa,CAAC;AACd;AACA;AACA,OAAO;AACP,KAAK;AACL,GAAG;AACH,CAAC;;;;"}
@@ -1,54 +0,0 @@
1
- 'use strict';
2
-
3
- var path = require('node:path');
4
- require('node:fs');
5
-
6
- /** @type {import('eslint').JSRuleDefinition} */
7
- var cssModuleNameMatchesRule = {
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- description:
12
- "enforce that a CSS module's filename matches the filename of the importing file",
13
- },
14
- schema: [],
15
- messages: {
16
- filenameMismatch:
17
- 'CSS module filename "{{cssModuleFilename}}" does not match the current filename "{{filename}}"',
18
- },
19
- },
20
- create(context) {
21
- return {
22
- ImportDeclaration(node) {
23
- if (
24
- typeof node.source.value !== 'string' ||
25
- !node.source.value.endsWith('.module.css')
26
- ) {
27
- return;
28
- }
29
-
30
- const filename = path.basename(
31
- context.filename,
32
- path.extname(context.filename),
33
- );
34
-
35
- const cssModulePath = node.source.value;
36
- const cssModuleFilename = path.basename(cssModulePath, '.module.css');
37
-
38
- if (cssModuleFilename !== filename) {
39
- context.report({
40
- node,
41
- messageId: 'filenameMismatch',
42
- data: {
43
- cssModuleFilename,
44
- filename,
45
- },
46
- });
47
- }
48
- },
49
- };
50
- },
51
- };
52
-
53
- module.exports = cssModuleNameMatchesRule;
54
- //# sourceMappingURL=css-module-name-matches.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"css-module-name-matches.js","sources":["../../../src/rules/css-module-name-matches.mjs"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs';\n\n/** @type {import('eslint').JSRuleDefinition} */\nexport default {\n meta: {\n type: 'problem',\n docs: {\n description:\n \"enforce that a CSS module's filename matches the filename of the importing file\",\n },\n schema: [],\n messages: {\n filenameMismatch:\n 'CSS module filename \"{{cssModuleFilename}}\" does not match the current filename \"{{filename}}\"',\n },\n },\n create(context) {\n return {\n ImportDeclaration(node) {\n if (\n typeof node.source.value !== 'string' ||\n !node.source.value.endsWith('.module.css')\n ) {\n return;\n }\n\n const filename = path.basename(\n context.filename,\n path.extname(context.filename),\n );\n\n const cssModulePath = node.source.value;\n const cssModuleFilename = path.basename(cssModulePath, '.module.css');\n\n if (cssModuleFilename !== filename) {\n context.report({\n node,\n messageId: 'filenameMismatch',\n data: {\n cssModuleFilename,\n filename,\n },\n });\n }\n },\n };\n },\n};\n"],"names":[],"mappings":";;;;;AAGA;AACA,+BAAe;AACf,EAAE,IAAI,EAAE;AACR,IAAI,IAAI,EAAE,SAAS;AACnB,IAAI,IAAI,EAAE;AACV,MAAM,WAAW;AACjB,QAAQ,iFAAiF;AACzF,KAAK;AACL,IAAI,MAAM,EAAE,EAAE;AACd,IAAI,QAAQ,EAAE;AACd,MAAM,gBAAgB;AACtB,QAAQ,gGAAgG;AACxG,KAAK;AACL,GAAG;AACH,EAAE,MAAM,CAAC,OAAO,EAAE;AAClB,IAAI,OAAO;AACX,MAAM,iBAAiB,CAAC,IAAI,EAAE;AAC9B,QAAQ;AACR,UAAU,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,QAAQ;AAC/C,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa;AACnD,UAAU;AACV,UAAU;AACV;;AAEA,QAAQ,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ;AACtC,UAAU,OAAO,CAAC,QAAQ;AAC1B,UAAU,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;AACxC,SAAS;;AAET,QAAQ,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK;AAC/C,QAAQ,MAAM,iBAAiB,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;;AAE7E,QAAQ,IAAI,iBAAiB,KAAK,QAAQ,EAAE;AAC5C,UAAU,OAAO,CAAC,MAAM,CAAC;AACzB,YAAY,IAAI;AAChB,YAAY,SAAS,EAAE,kBAAkB;AACzC,YAAY,IAAI,EAAE;AAClB,cAAc,iBAAiB;AAC/B,cAAc,QAAQ;AACtB,aAAa;AACb,WAAW,CAAC;AACZ;AACA,OAAO;AACP,KAAK;AACL,GAAG;AACH,CAAC;;;;"}
@@ -1,213 +0,0 @@
1
- import path from 'node:path';
2
- import fs from 'node:fs';
3
- import { parse } from 'postcss';
4
- import selectorParser from 'postcss-selector-parser';
5
-
6
- /** @type {import('eslint').JSRuleDefinition} */
7
- var cssModuleClassExistsRule = {
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- description:
12
- 'enforce that class names used from an imported CSS module exist in the module file',
13
- },
14
- schema: [],
15
- messages: {
16
- relativePath:
17
- 'CSS module import "{{importPath}}" should be a relative path',
18
- defaultImport:
19
- 'CSS module import "{{importPath}}" should have a default import',
20
- onlyDefaultImport:
21
- 'CSS module import "{{importPath}}" should have only a default import',
22
- fileDoesNotExist:
23
- 'CSS module file "{{absoluteImportPath}}" does not exist',
24
- classDoesNotExist:
25
- 'Class `.{{className}}` does not exist in the CSS module imported as `{{objectName}}`',
26
- },
27
- },
28
- create(context) {
29
- const classNames = {};
30
-
31
- return {
32
- ImportDeclaration(node) {
33
- if (
34
- typeof node.source.value !== 'string' ||
35
- !node.source.value.endsWith('.module.css')
36
- ) {
37
- return;
38
- }
39
-
40
- const importPath = node.source.value;
41
-
42
- if (!(importPath.startsWith('./') || importPath.startsWith('../'))) {
43
- context.report({
44
- node,
45
- messageId: 'relativePath',
46
- data: { importPath },
47
- });
48
-
49
- return;
50
- }
51
-
52
- if (node.specifiers.length === 0) {
53
- context.report({
54
- node,
55
- messageId: 'defaultImport',
56
- data: { importPath },
57
- });
58
-
59
- return;
60
- }
61
-
62
- if (node.specifiers.length > 1) {
63
- context.report({
64
- node,
65
- messageId: 'onlyDefaultImport',
66
- data: { importPath },
67
- });
68
-
69
- return;
70
- }
71
-
72
- const defaultImportSpecifier = node.specifiers.find(
73
- (specifier) => specifier.type === 'ImportDefaultSpecifier',
74
- );
75
-
76
- if (defaultImportSpecifier == null) {
77
- context.report({
78
- node,
79
- messageId: 'onlyDefaultImport',
80
- data: { importPath },
81
- });
82
-
83
- return;
84
- }
85
-
86
- const dirname = path.dirname(context.physicalFilename);
87
- const absoluteImportPath = path.resolve(dirname, importPath);
88
-
89
- if (!fs.existsSync(absoluteImportPath)) {
90
- context.report({
91
- node,
92
- messageId: 'fileDoesNotExist',
93
- data: { absoluteImportPath },
94
- });
95
-
96
- return;
97
- }
98
-
99
- const importName = defaultImportSpecifier.local.name;
100
-
101
- classNames[importName] = new Set();
102
-
103
- const cssModuleContent = fs.readFileSync(absoluteImportPath, 'utf8');
104
- const root = parse(cssModuleContent);
105
-
106
- for (const node of root.nodes) {
107
- if (node.type === 'rule') {
108
- selectorParser(function transform(selectors) {
109
- selectors.walkClasses((classNode) => {
110
- classNames[importName].add(classNode.value);
111
- });
112
- }).processSync(node.selector);
113
- } else if (
114
- node.type === 'atrule' &&
115
- (node.name === 'media' ||
116
- node.name === 'container' ||
117
- node.name === 'layer')
118
- ) {
119
- for (const childNode of node.nodes) {
120
- if (childNode.type !== 'rule') {
121
- continue;
122
- }
123
-
124
- selectorParser(function transform(selectors) {
125
- selectors.walkClasses((classNode) => {
126
- classNames[importName].add(classNode.value);
127
- });
128
- }).processSync(childNode.selector);
129
- }
130
- }
131
- }
132
- },
133
- MemberExpression(node) {
134
- if (node.object.type !== 'Identifier') {
135
- return;
136
- }
137
-
138
- if (classNames[node.object.name] == null) {
139
- return;
140
- }
141
-
142
- const objectName = node.object.name;
143
-
144
- if (node.property.type === 'Identifier') {
145
- const className = node.property.name;
146
-
147
- if (!classNames[objectName].has(className)) {
148
- context.report({
149
- node,
150
- messageId: 'classDoesNotExist',
151
- data: { className, objectName },
152
- });
153
- }
154
-
155
- return;
156
- }
157
-
158
- if (
159
- node.property.type === 'Literal' &&
160
- typeof node.property.value === 'string'
161
- ) {
162
- const className = node.property.value;
163
-
164
- if (!classNames[objectName].has(className)) {
165
- context.report({
166
- node,
167
- messageId: 'classDoesNotExist',
168
- data: { className, objectName },
169
- });
170
- }
171
- }
172
- },
173
- VariableDeclarator(node) {
174
- if (node.id.type !== 'ObjectPattern') {
175
- return;
176
- }
177
-
178
- if (node.init?.type !== 'Identifier') {
179
- return;
180
- }
181
-
182
- const objectName = node.init.name;
183
-
184
- if (classNames[objectName] == null) {
185
- return;
186
- }
187
-
188
- for (const property of node.id.properties) {
189
- if (property.type !== 'Property') {
190
- continue;
191
- }
192
-
193
- if (property.key.type !== 'Identifier') {
194
- continue;
195
- }
196
-
197
- const className = property.key.name;
198
-
199
- if (!classNames[objectName].has(className)) {
200
- context.report({
201
- node: property,
202
- messageId: 'classDoesNotExist',
203
- data: { className, objectName },
204
- });
205
- }
206
- }
207
- },
208
- };
209
- },
210
- };
211
-
212
- export { cssModuleClassExistsRule as default };
213
- //# sourceMappingURL=css-module-class-exists.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"css-module-class-exists.js","sources":["../../../src/rules/css-module-class-exists.mjs"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs';\n\nimport { parse } from 'postcss';\nimport selectorParser from 'postcss-selector-parser';\n\n/** @type {import('eslint').JSRuleDefinition} */\nexport default {\n meta: {\n type: 'problem',\n docs: {\n description:\n 'enforce that class names used from an imported CSS module exist in the module file',\n },\n schema: [],\n messages: {\n relativePath:\n 'CSS module import \"{{importPath}}\" should be a relative path',\n defaultImport:\n 'CSS module import \"{{importPath}}\" should have a default import',\n onlyDefaultImport:\n 'CSS module import \"{{importPath}}\" should have only a default import',\n fileDoesNotExist:\n 'CSS module file \"{{absoluteImportPath}}\" does not exist',\n classDoesNotExist:\n 'Class `.{{className}}` does not exist in the CSS module imported as `{{objectName}}`',\n },\n },\n create(context) {\n const classNames = {};\n\n return {\n ImportDeclaration(node) {\n if (\n typeof node.source.value !== 'string' ||\n !node.source.value.endsWith('.module.css')\n ) {\n return;\n }\n\n const importPath = node.source.value;\n\n if (!(importPath.startsWith('./') || importPath.startsWith('../'))) {\n context.report({\n node,\n messageId: 'relativePath',\n data: { importPath },\n });\n\n return;\n }\n\n if (node.specifiers.length === 0) {\n context.report({\n node,\n messageId: 'defaultImport',\n data: { importPath },\n });\n\n return;\n }\n\n if (node.specifiers.length > 1) {\n context.report({\n node,\n messageId: 'onlyDefaultImport',\n data: { importPath },\n });\n\n return;\n }\n\n const defaultImportSpecifier = node.specifiers.find(\n (specifier) => specifier.type === 'ImportDefaultSpecifier',\n );\n\n if (defaultImportSpecifier == null) {\n context.report({\n node,\n messageId: 'onlyDefaultImport',\n data: { importPath },\n });\n\n return;\n }\n\n const dirname = path.dirname(context.physicalFilename);\n const absoluteImportPath = path.resolve(dirname, importPath);\n\n if (!fs.existsSync(absoluteImportPath)) {\n context.report({\n node,\n messageId: 'fileDoesNotExist',\n data: { absoluteImportPath },\n });\n\n return;\n }\n\n const importName = defaultImportSpecifier.local.name;\n\n classNames[importName] = new Set();\n\n const cssModuleContent = fs.readFileSync(absoluteImportPath, 'utf8');\n const root = parse(cssModuleContent);\n\n for (const node of root.nodes) {\n if (node.type === 'rule') {\n selectorParser(function transform(selectors) {\n selectors.walkClasses((classNode) => {\n classNames[importName].add(classNode.value);\n });\n }).processSync(node.selector);\n } else if (\n node.type === 'atrule' &&\n (node.name === 'media' ||\n node.name === 'container' ||\n node.name === 'layer')\n ) {\n for (const childNode of node.nodes) {\n if (childNode.type !== 'rule') {\n continue;\n }\n\n selectorParser(function transform(selectors) {\n selectors.walkClasses((classNode) => {\n classNames[importName].add(classNode.value);\n });\n }).processSync(childNode.selector);\n }\n }\n }\n },\n MemberExpression(node) {\n if (node.object.type !== 'Identifier') {\n return;\n }\n\n if (classNames[node.object.name] == null) {\n return;\n }\n\n const objectName = node.object.name;\n\n if (node.property.type === 'Identifier') {\n const className = node.property.name;\n\n if (!classNames[objectName].has(className)) {\n context.report({\n node,\n messageId: 'classDoesNotExist',\n data: { className, objectName },\n });\n }\n\n return;\n }\n\n if (\n node.property.type === 'Literal' &&\n typeof node.property.value === 'string'\n ) {\n const className = node.property.value;\n\n if (!classNames[objectName].has(className)) {\n context.report({\n node,\n messageId: 'classDoesNotExist',\n data: { className, objectName },\n });\n }\n }\n },\n VariableDeclarator(node) {\n if (node.id.type !== 'ObjectPattern') {\n return;\n }\n\n if (node.init?.type !== 'Identifier') {\n return;\n }\n\n const objectName = node.init.name;\n\n if (classNames[objectName] == null) {\n return;\n }\n\n for (const property of node.id.properties) {\n if (property.type !== 'Property') {\n continue;\n }\n\n if (property.key.type !== 'Identifier') {\n continue;\n }\n\n const className = property.key.name;\n\n if (!classNames[objectName].has(className)) {\n context.report({\n node: property,\n messageId: 'classDoesNotExist',\n data: { className, objectName },\n });\n }\n }\n },\n };\n },\n};\n"],"names":[],"mappings":";;;;;AAMA;AACA,+BAAe;AACf,EAAE,IAAI,EAAE;AACR,IAAI,IAAI,EAAE,SAAS;AACnB,IAAI,IAAI,EAAE;AACV,MAAM,WAAW;AACjB,QAAQ,oFAAoF;AAC5F,KAAK;AACL,IAAI,MAAM,EAAE,EAAE;AACd,IAAI,QAAQ,EAAE;AACd,MAAM,YAAY;AAClB,QAAQ,8DAA8D;AACtE,MAAM,aAAa;AACnB,QAAQ,iEAAiE;AACzE,MAAM,iBAAiB;AACvB,QAAQ,sEAAsE;AAC9E,MAAM,gBAAgB;AACtB,QAAQ,yDAAyD;AACjE,MAAM,iBAAiB;AACvB,QAAQ,sFAAsF;AAC9F,KAAK;AACL,GAAG;AACH,EAAE,MAAM,CAAC,OAAO,EAAE;AAClB,IAAI,MAAM,UAAU,GAAG,EAAE;;AAEzB,IAAI,OAAO;AACX,MAAM,iBAAiB,CAAC,IAAI,EAAE;AAC9B,QAAQ;AACR,UAAU,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,QAAQ;AAC/C,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa;AACnD,UAAU;AACV,UAAU;AACV;;AAEA,QAAQ,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK;;AAE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G;AACH,CAAC;;;;"}
@@ -1,52 +0,0 @@
1
- import path from 'node:path';
2
- import 'node:fs';
3
-
4
- /** @type {import('eslint').JSRuleDefinition} */
5
- var cssModuleNameMatchesRule = {
6
- meta: {
7
- type: 'problem',
8
- docs: {
9
- description:
10
- "enforce that a CSS module's filename matches the filename of the importing file",
11
- },
12
- schema: [],
13
- messages: {
14
- filenameMismatch:
15
- 'CSS module filename "{{cssModuleFilename}}" does not match the current filename "{{filename}}"',
16
- },
17
- },
18
- create(context) {
19
- return {
20
- ImportDeclaration(node) {
21
- if (
22
- typeof node.source.value !== 'string' ||
23
- !node.source.value.endsWith('.module.css')
24
- ) {
25
- return;
26
- }
27
-
28
- const filename = path.basename(
29
- context.filename,
30
- path.extname(context.filename),
31
- );
32
-
33
- const cssModulePath = node.source.value;
34
- const cssModuleFilename = path.basename(cssModulePath, '.module.css');
35
-
36
- if (cssModuleFilename !== filename) {
37
- context.report({
38
- node,
39
- messageId: 'filenameMismatch',
40
- data: {
41
- cssModuleFilename,
42
- filename,
43
- },
44
- });
45
- }
46
- },
47
- };
48
- },
49
- };
50
-
51
- export { cssModuleNameMatchesRule as default };
52
- //# sourceMappingURL=css-module-name-matches.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"css-module-name-matches.js","sources":["../../../src/rules/css-module-name-matches.mjs"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs';\n\n/** @type {import('eslint').JSRuleDefinition} */\nexport default {\n meta: {\n type: 'problem',\n docs: {\n description:\n \"enforce that a CSS module's filename matches the filename of the importing file\",\n },\n schema: [],\n messages: {\n filenameMismatch:\n 'CSS module filename \"{{cssModuleFilename}}\" does not match the current filename \"{{filename}}\"',\n },\n },\n create(context) {\n return {\n ImportDeclaration(node) {\n if (\n typeof node.source.value !== 'string' ||\n !node.source.value.endsWith('.module.css')\n ) {\n return;\n }\n\n const filename = path.basename(\n context.filename,\n path.extname(context.filename),\n );\n\n const cssModulePath = node.source.value;\n const cssModuleFilename = path.basename(cssModulePath, '.module.css');\n\n if (cssModuleFilename !== filename) {\n context.report({\n node,\n messageId: 'filenameMismatch',\n data: {\n cssModuleFilename,\n filename,\n },\n });\n }\n },\n };\n },\n};\n"],"names":[],"mappings":";;;AAGA;AACA,+BAAe;AACf,EAAE,IAAI,EAAE;AACR,IAAI,IAAI,EAAE,SAAS;AACnB,IAAI,IAAI,EAAE;AACV,MAAM,WAAW;AACjB,QAAQ,iFAAiF;AACzF,KAAK;AACL,IAAI,MAAM,EAAE,EAAE;AACd,IAAI,QAAQ,EAAE;AACd,MAAM,gBAAgB;AACtB,QAAQ,gGAAgG;AACxG,KAAK;AACL,GAAG;AACH,EAAE,MAAM,CAAC,OAAO,EAAE;AAClB,IAAI,OAAO;AACX,MAAM,iBAAiB,CAAC,IAAI,EAAE;AAC9B,QAAQ;AACR,UAAU,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,QAAQ;AAC/C,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa;AACnD,UAAU;AACV,UAAU;AACV;;AAEA,QAAQ,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ;AACtC,UAAU,OAAO,CAAC,QAAQ;AAC1B,UAAU,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;AACxC,SAAS;;AAET,QAAQ,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK;AAC/C,QAAQ,MAAM,iBAAiB,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;;AAE7E,QAAQ,IAAI,iBAAiB,KAAK,QAAQ,EAAE;AAC5C,UAAU,OAAO,CAAC,MAAM,CAAC;AACzB,YAAY,IAAI;AAChB,YAAY,SAAS,EAAE,kBAAkB;AACzC,YAAY,IAAI,EAAE;AAClB,cAAc,iBAAiB;AAC/B,cAAc,QAAQ;AACtB,aAAa;AACb,WAAW,CAAC;AACZ;AACA,OAAO;AACP,KAAK;AACL,GAAG;AACH,CAAC;;;;"}