Merge pull request #2684 from themousepotato/lintrule-dirname-fix

Add a lint rule to avoid using __dirname
This commit is contained in:
Patrik Oldsberg
2020-10-09 21:03:13 +02:00
committed by GitHub
18 changed files with 24 additions and 0 deletions
+1
View File
@@ -21,6 +21,7 @@ import { loadConfig } from '@backstage/config-loader';
* Load configuration for a Backend
*/
export async function loadBackendConfig() {
/* eslint-disable-next-line no-restricted-syntax */
const paths = findPaths(__dirname);
const configs = await loadConfig({
env: process.env.NODE_ENV ?? 'development',
+1
View File
@@ -14,6 +14,7 @@
* limitations under the License.
*/
/* eslint-disable no-restricted-syntax */
import { resolve as resolvePath } from 'path';
import { findPaths, findRootPath, findOwnDir, findOwnRootDir } from './paths';
+2
View File
@@ -18,6 +18,7 @@
const path = require('path');
// Figure out whether we're running inside the backstage repo or as an installed dependency
/* eslint-disable-next-line no-restricted-syntax */
const isLocal = require('fs').existsSync(path.resolve(__dirname, '../src'));
if (!isLocal || process.env.BACKSTAGE_E2E_CLI_TEST) {
@@ -25,6 +26,7 @@ if (!isLocal || process.env.BACKSTAGE_E2E_CLI_TEST) {
} else {
require('ts-node').register({
transpileOnly: true,
/* eslint-disable-next-line no-restricted-syntax */
project: path.resolve(__dirname, '../../../tsconfig.json'),
compilerOptions: {
module: 'CommonJS',
+5
View File
@@ -67,6 +67,11 @@ module.exports = {
selector:
'ImportDeclaration[source.value="winston"] ImportDefaultSpecifier',
},
{
message:
"`__dirname` doesn't refer to the same dir in production builds, try `resolvePackagePath()` from `@backstage/backend-common` instead.",
selector: 'Identifier[name="__dirname"]',
},
],
},
overrides: [
+1
View File
@@ -209,6 +209,7 @@ export async function createBackendConfig(
],
target: 'node' as const,
node: {
/* eslint-disable-next-line no-restricted-syntax */
__dirname: true,
__filename: true,
global: true,
+1
View File
@@ -16,4 +16,5 @@
import { findPaths } from '@backstage/cli-common';
/* eslint-disable-next-line no-restricted-syntax */
export const paths = findPaths(__dirname);
@@ -15,6 +15,7 @@
* limitations under the License.
*/
/* eslint-disable no-restricted-syntax */
const path = require('path');
// Figure out whether we're running inside the backstage repo or as an installed dependency
+1
View File
@@ -87,6 +87,7 @@ async function moveApp(tempDir: string, destination: string, id: string) {
}
export default async (cmd: Command): Promise<void> => {
/* eslint-disable-next-line no-restricted-syntax */
const paths = findPaths(__dirname);
const questions: Question[] = [
+1
View File
@@ -15,6 +15,7 @@
* limitations under the License.
*/
/* eslint-disable no-restricted-syntax */
const path = require('path');
// Figure out whether we're running inside the backstage repo or as an installed dependency
+1
View File
@@ -37,6 +37,7 @@ export async function generate(
);
}
/* eslint-disable-next-line no-restricted-syntax */
const rootDir = resolvePath(__dirname, '../../..');
const srcDir = resolvePath(rootDir, 'packages', 'core-api', 'src');
const targetDir = resolvePath(targetPath);
+1
View File
@@ -21,6 +21,7 @@ import fs from 'fs-extra';
import { generate } from './generate';
const main = (argv: string[]) => {
/* eslint-disable-next-line no-restricted-syntax */
const pkgJson = fs.readJsonSync(resolvePath(__dirname, '../package.json'));
program.name('docgen').version(pkgJson.version);
+1
View File
@@ -33,6 +33,7 @@ import {
import pgtools from 'pgtools';
import { findPaths } from '@backstage/cli-common';
/* eslint-disable-next-line no-restricted-syntax */
const paths = findPaths(__dirname);
const templatePackagePaths = [
+1
View File
@@ -16,6 +16,7 @@
require('ts-node').register({
transpileOnly: true,
/* eslint-disable-next-line no-restricted-syntax */
project: require('path').resolve(__dirname, '../../../tsconfig.json'),
compilerOptions: {
module: 'CommonJS',
+1
View File
@@ -14,6 +14,7 @@ module.exports = {
'storybook-dark-mode/register',
],
webpackFinal: async config => {
/* eslint-disable-next-line no-restricted-syntax */
const coreSrc = path.resolve(__dirname, '../../core/src');
// Mirror config in packages/cli/src/lib/bundler
+1
View File
@@ -15,6 +15,7 @@
* limitations under the License.
*/
/* eslint-disable no-restricted-syntax */
const path = require('path');
// Figure out whether we're running inside the backstage repo or as an installed dependency
+1
View File
@@ -101,6 +101,7 @@ const main = (argv: string[]) => {
// Local Backstage Preview
const techdocsPreviewBundlePath = path.join(
/* eslint-disable-next-line no-restricted-syntax */
__dirname,
'..',
'dist',
@@ -25,6 +25,7 @@ import { createRouter } from './router';
jest.mock('../lib/config', () => ({ injectEnvConfig: jest.fn() }));
global.__non_webpack_require__ = {
/* eslint-disable-next-line no-restricted-syntax */
resolve: () => resolvePath(__dirname, '__fixtures__/app-dir/package.json'),
};
@@ -13,6 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable no-restricted-syntax */
import fs from 'fs-extra';
import path from 'path';
import { getVoidLogger } from '@backstage/backend-common';