Disallowing access to the backend-core barrel file as it can cause problems, it should only ever be imported externally via @budibase/backend-core.
This commit is contained in:
parent
5e35e633c0
commit
26871a7deb
|
@ -43,6 +43,7 @@
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"no-unused-vars": "off",
|
"no-unused-vars": "off",
|
||||||
|
"local-rules/no-barrel-imports": "error",
|
||||||
"local-rules/no-budibase-imports": "error",
|
"local-rules/no-budibase-imports": "error",
|
||||||
"local-rules/no-console-error": "error",
|
"local-rules/no-console-error": "error",
|
||||||
"@typescript-eslint/no-unused-vars": [
|
"@typescript-eslint/no-unused-vars": [
|
||||||
|
|
|
@ -1,6 +1,17 @@
|
||||||
|
const path = require("path")
|
||||||
|
|
||||||
|
const makeBarrelPath = finalPath => {
|
||||||
|
return path.resolve(__dirname, "..", finalPath)
|
||||||
|
}
|
||||||
|
const backendCoreBarrelPaths = [
|
||||||
|
makeBarrelPath(path.join("packages", "backend-core", "src", "index.ts")),
|
||||||
|
makeBarrelPath(path.join("packages", "backend-core", "src")),
|
||||||
|
makeBarrelPath(path.join("packages", "backend-core")),
|
||||||
|
]
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"no-console-error": {
|
"no-console-error": {
|
||||||
create: function(context) {
|
create: function (context) {
|
||||||
return {
|
return {
|
||||||
CallExpression(node) {
|
CallExpression(node) {
|
||||||
if (
|
if (
|
||||||
|
@ -13,11 +24,12 @@ module.exports = {
|
||||||
) {
|
) {
|
||||||
context.report({
|
context.report({
|
||||||
node,
|
node,
|
||||||
message: 'Using console.error(err) on its own is not allowed. Either provide context to the error (console.error(msg, err)) or throw it.',
|
message:
|
||||||
|
"Using console.error(err) on its own is not allowed. Either provide context to the error (console.error(msg, err)) or throw it.",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"no-budibase-imports": {
|
"no-budibase-imports": {
|
||||||
|
@ -106,4 +118,42 @@ module.exports = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"no-barrel-imports": {
|
||||||
|
meta: {
|
||||||
|
type: "problem",
|
||||||
|
docs: {
|
||||||
|
description:
|
||||||
|
"Disallow imports from the top-level backend-core barrel file",
|
||||||
|
category: "Best Practices",
|
||||||
|
recommended: false,
|
||||||
|
},
|
||||||
|
schema: [], // no options
|
||||||
|
messages: {
|
||||||
|
noBarrelImport:
|
||||||
|
"Avoid importing from the top-level barrel file 'backend-core/src/index.ts'. Import directly from the specific module instead.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
create(context) {
|
||||||
|
return {
|
||||||
|
ImportDeclaration(node) {
|
||||||
|
const importPath = node.source.value
|
||||||
|
const importFullPath = path.resolve(
|
||||||
|
context.getFilename(),
|
||||||
|
"..",
|
||||||
|
importPath
|
||||||
|
)
|
||||||
|
|
||||||
|
if (backendCoreBarrelPaths.includes(importFullPath)) {
|
||||||
|
context.report({
|
||||||
|
node,
|
||||||
|
messageId: "noBarrelImport",
|
||||||
|
data: {
|
||||||
|
importFullPath,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { testEnv } from "../../../tests/extra"
|
||||||
import * as context from "../"
|
import * as context from "../"
|
||||||
import { DEFAULT_TENANT_ID } from "../../constants"
|
import { DEFAULT_TENANT_ID } from "../../constants"
|
||||||
import { structures } from "../../../tests"
|
import { structures } from "../../../tests"
|
||||||
import { db } from "../.."
|
import * as db from "../../db"
|
||||||
import Context from "../Context"
|
import Context from "../Context"
|
||||||
import { ContextMap } from "../types"
|
import { ContextMap } from "../types"
|
||||||
import { IdentityType } from "@budibase/types"
|
import { IdentityType } from "@budibase/types"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { IdentityContext, IdentityType, UserCtx } from "@budibase/types"
|
import { IdentityContext, IdentityType, UserCtx } from "@budibase/types"
|
||||||
import { Flag, FlagSet, FlagValues, init, shutdown } from "../"
|
import { Flag, FlagSet, FlagValues, init, shutdown } from "../"
|
||||||
import { context } from "../.."
|
import * as context from "../../context"
|
||||||
import environment, { withEnv } from "../../environment"
|
import environment, { withEnv } from "../../environment"
|
||||||
import nodeFetch from "node-fetch"
|
import nodeFetch from "node-fetch"
|
||||||
import nock from "nock"
|
import nock from "nock"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { GenericContainer, StartedTestContainer } from "testcontainers"
|
import { GenericContainer, StartedTestContainer } from "testcontainers"
|
||||||
import { generator, structures } from "../../../tests"
|
import { generator, structures } from "../../../tests"
|
||||||
import RedisWrapper, { closeAll } from "../redis"
|
import RedisWrapper, { closeAll } from "../redis"
|
||||||
import { env } from "../.."
|
import env from "../../environment"
|
||||||
import { randomUUID } from "crypto"
|
import { randomUUID } from "crypto"
|
||||||
|
|
||||||
jest.setTimeout(30000)
|
jest.setTimeout(30000)
|
||||||
|
|
Loading…
Reference in New Issue