mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 01:38:07 +08:00
imported exist in the file system. Initally, we wanted to create a `.d.ts` file for each CSS file to ensure that the file being imported actually exists. However, when ninja is building `tsc` uses the generated `tsconfig` file in `gen`. In the `tsconfig.json` `files` list it will see the original TS file that's in the source tree. When it goes to see the TS file and sees the `import styles from 'foo.css.js'`. However, that file does not exist in the files list of the entrypoint or the source tree, so TS never finds it. Instead we went with the approach of adding a `declare module` to type all `.css.js` files and then use a lint rule to ensure that if you import `foo.css.js` that there is a `foo.css` file in the tree. Bug: 1106746 Change-Id: I8a65734bf4a9b359f8210b0011f14800c5d9426b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2953260 Commit-Queue: Kriti Sapra <kritisapra@google.com> Commit-Queue: Paul Lewis <aerotwist@chromium.org> Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
// 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');
|
|
|
|
module.exports = {
|
|
meta: {
|
|
type: 'problem',
|
|
|
|
docs: {
|
|
description: 'check CSS file imports',
|
|
category: 'Possible Errors',
|
|
},
|
|
fixable: 'code',
|
|
schema: [] // no options
|
|
},
|
|
create: function(context) {
|
|
return {
|
|
ImportDeclaration(node) {
|
|
const importPath = path.normalize(node.source.value);
|
|
|
|
if (importPath.endsWith('.css.js')) {
|
|
const importingFileName = path.resolve(context.getFilename());
|
|
const exportingFileName = path.resolve(path.dirname(importingFileName), importPath);
|
|
const importedCSS = exportingFileName.replace(/\.js$/, '');
|
|
|
|
if (!fs.existsSync(importedCSS)) {
|
|
context.report({
|
|
node,
|
|
message: `File ${path.basename(importedCSS)} does not exist. Check you are importing the correct file.`
|
|
});
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
};
|