forked from ChromeDevTools/devtools-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-css-import.js
53 lines (46 loc) · 1.55 KB
/
check-css-import.js
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
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* @fileoverview Prevent usage of customElements.define() and use the helper
* function instead
*/
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
const fs = require('fs');
const path = require('path');
/**
* @type {import('eslint').Rule.RuleModule}
*/
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'check CSS file imports',
category: 'Possible Errors',
},
fixable: 'code',
schema: [] // no options
},
create: function(context) {
const filename = context.filename ?? context.getFilename();
return {
ImportDeclaration(node) {
const importPath = path.normalize(node.source.value);
if (importPath.endsWith('.css.js') || importPath.endsWith('.css.legacy.js')) {
const importingFileName = path.resolve(filename);
const exportingFileName = path.resolve(path.dirname(importingFileName), importPath);
const importedCSS = exportingFileName.replace(/(\.legacy)?\.js$/, '');
if (!fs.existsSync(importedCSS)) {
context.report({
node,
message: `File ${path.basename(importedCSS)} does not exist. Check you are importing the correct file.`
});
}
}
}
};
}
};