Skip to content

Commit

Permalink
Merge pull request #15143 from Budibase/eslint-strict-1
Browse files Browse the repository at this point in the history
Enable a variety of useful looking lints.
  • Loading branch information
samwho authored Dec 9, 2024
2 parents 2b02911 + 1c476e0 commit 40d7324
Show file tree
Hide file tree
Showing 56 changed files with 123 additions and 202 deletions.
132 changes: 76 additions & 56 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,23 @@ export default [
},

rules: {
"no-self-assign": "off",
"prefer-const": "off",
"no-self-compare": "error",
"no-template-curly-in-string": "error",
"no-unmodified-loop-condition": "error",
"no-unreachable-loop": "error",
"no-implied-eval": "error",
"no-extend-native": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-return-assign": "error",
"no-useless-concat": "error",
"no-useless-constructor": "error",
"no-useless-rename": "error",
"no-var": "error",
"no-void": "error",

"no-unused-vars": [
"error",
{
Expand All @@ -65,64 +80,69 @@ export default [
],
},
},
...eslintPluginSvelte.configs["flat/recommended"].map(config => {
return {
...config,
files: ["**/*.svelte"],

languageOptions: {
parser: svelteParser,
ecmaVersion: 2019,
sourceType: "script",

parserOptions: {
parser: "@typescript-eslint/parser",
allowImportExportEverywhere: true,
},
},
}
}),
...tseslint.configs.recommended.map(config => {
return {
...config,
files: ["**/*.ts"],

languageOptions: {
globals: {
NodeJS: true,
},
...eslintPluginSvelte.configs["flat/recommended"].map(config => ({
...config,
files: ["**/*.svelte"],

parser: tsParser,
languageOptions: {
parser: svelteParser,
ecmaVersion: 2019,
sourceType: "script",

parserOptions: {
parser: "@typescript-eslint/parser",
allowImportExportEverywhere: true,
},
},
})),
...tseslint.configs.strict.map(config => ({
...config,
files: ["**/*.ts"],

rules: {
"local-rules/no-barrel-imports": "error",
"local-rules/no-budibase-imports": "error",
"local-rules/no-console-error": "error",

// @typscript-eslint/no-unused-vars supersedes no-unused-vars
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
varsIgnorePattern: "^_",
argsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
ignoreRestSiblings: true,
caughtErrors: "none",
},
],

// @typescript-eslint/no-redeclare supersedes no-redeclare
"no-redeclare": "off",
"@typescript-eslint/no-redeclare": "error",

// @typescript-eslint/no-dupe-class-members supersedes no-dupe-class-members
"no-dupe-class-members": "off",
"@typescript-eslint/no-dupe-class-members": "error",
languageOptions: {
globals: {
NodeJS: true,
},
}
}),

parser: tsParser,
},

rules: {
"local-rules/no-barrel-imports": "error",
"local-rules/no-budibase-imports": "error",
"local-rules/no-console-error": "error",

"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/class-literal-property-style": "error",
"@typescript-eslint/no-confusing-non-null-assertion": "error",
"@typescript-eslint/no-unnecessary-parameter-property-assignment":
"error",
"@typescript-eslint/no-useless-empty-export": "error",

"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
varsIgnorePattern: "^_",
argsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
ignoreRestSiblings: true,
caughtErrors: "none",
},
],

"no-redeclare": "off",
"@typescript-eslint/no-redeclare": "error",

// @typescript-eslint/no-dupe-class-members supersedes no-dupe-class-members
"no-dupe-class-members": "off",
"@typescript-eslint/no-dupe-class-members": "error",

"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "error",
},
})),
{
files: ["**/*.spec.ts", "**/*.spec.js"],

Expand Down
2 changes: 1 addition & 1 deletion packages/backend-core/src/db/couch/DatabaseImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class DatabaseImpl implements Database {
return
}
let errorFound = false
let errorMessage: string = "Unable to bulk remove documents: "
let errorMessage = "Unable to bulk remove documents: "
for (let res of response) {
if (res.error) {
errorFound = true
Expand Down
4 changes: 2 additions & 2 deletions packages/backend-core/src/db/couch/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { checkSlashesInUrl } from "../../helpers"

export async function directCouchCall(
path: string,
method: string = "GET",
method = "GET",
body?: any
) {
let { url, cookie } = getCouchInfo()
Expand Down Expand Up @@ -43,7 +43,7 @@ export async function directCouchUrlCall({

export async function directCouchQuery(
path: string,
method: string = "GET",
method = "GET",
body?: any
) {
const response = await directCouchCall(path, method, body)
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-core/src/db/lucene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export class QueryBuilder<T> {
let query = allOr ? "" : "*:*"
let allFiltersEmpty = true
const allPreProcessingOpts = { escape: true, lowercase: true, wrap: true }
let tableId: string = ""
let tableId = ""
if (this.#query.equal!.tableId) {
tableId = this.#query.equal!.tableId
delete this.#query.equal!.tableId
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-core/src/events/processors/Processors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Event, Identity, Group } from "@budibase/types"
import { EventProcessor } from "./types"

export default class Processor implements EventProcessor {
initialised: boolean = false
initialised = false
processors: EventProcessor[] = []

constructor(processors: EventProcessor[]) {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend-core/src/middleware/authenticated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ export default function (
}

const tenantId = getHeader(ctx, Header.TENANT_ID)
let authenticated: boolean = false,
let authenticated = false,
user: User | { tenantId: string } | undefined = undefined,
internal: boolean = false,
internal = false,
loginMethod: LoginMethod | undefined = undefined
if (authCookie && !apiKey) {
const sessionId = authCookie.sessionId
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-core/src/middleware/passport/sso/sso.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const ssoSaveUserNoOp: SaveSSOUserFunction = (user: SSOUser) =>
*/
export async function authenticate(
details: SSOAuthDetails,
requireLocalAccount: boolean = true,
requireLocalAccount = true,
done: any,
saveUserFn: SaveSSOUserFunction
) {
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-core/src/objectStore/objectStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export async function listAllObjects(bucketName: string, path: string) {
export function getPresignedUrl(
bucketName: string,
key: string,
durationSeconds: number = 3600
durationSeconds = 3600
) {
const objectStore = ObjectStore(bucketName, { presigning: true })
const params = {
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-core/src/redis/redlockImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function getLockName(opts: LockOptions) {
// determine lock name
// by default use the tenantId for uniqueness, unless using a system lock
const prefix = opts.systemLock ? "system" : context.getTenantId()
let name: string = `lock:${prefix}_${opts.name}`
let name = `lock:${prefix}_${opts.name}`
// add additional unique name if required
if (opts.resource) {
name = name + `_${opts.resource}`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MonthlyQuotaName, QuotaUsage } from "@budibase/types"

export const usage = (users: number = 0, creators: number = 0): QuotaUsage => {
export const usage = (users = 0, creators = 0): QuotaUsage => {
return {
_id: "usage_quota",
quotaReset: new Date().toISOString(),
Expand Down
2 changes: 1 addition & 1 deletion packages/bbui/src/Form/Core/Signature.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
}
const getPos = e => {
var rect = canvasRef.getBoundingClientRect()
let rect = canvasRef.getBoundingClientRect()
const canvasX = e.offsetX || e.targetTouches?.[0].pageX - rect.left
const canvasY = e.offsetY || e.targetTouches?.[0].pageY - rect.top
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
const j = 32 // Outer radius strength (higher is stronger)
// Calculate unit vector
var dx = x1 - x2
var dy = y1 - y2
var len = Math.sqrt(dx * dx + dy * dy)
let dx = x1 - x2
let dy = y1 - y2
let len = Math.sqrt(dx * dx + dy * dy)
dx = dx / len
dy = dy / len
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const FullScreenControl = L.Control.extend({
fullScreenTitle: "Enter Fullscreen",
},
onAdd: function () {
var fullScreenClassName = "leaflet-control-fullscreen",
let fullScreenClassName = "leaflet-control-fullscreen",
container = L.DomUtil.create("div", fullScreenClassName + " leaflet-bar"),
options = this.options

Expand All @@ -45,7 +45,7 @@ const FullScreenControl = L.Control.extend({
return container
},
_fullScreen: function () {
var map = this._map
let map = this._map
if (screenfull.isEnabled) {
screenfull.toggle(map.getContainer())
}
Expand Down Expand Up @@ -80,7 +80,7 @@ const LocationControl = L.Control.extend({
locationTitle: "Show Your Location",
},
onAdd: function () {
var locationClassName = "leaflet-control-location",
let locationClassName = "leaflet-control-location",
container = L.DomUtil.create("div", locationClassName + " leaflet-bar"),
options = this.options

Expand Down Expand Up @@ -136,7 +136,7 @@ const LocationControl = L.Control.extend({
})
},
_getPosition: function () {
var options = {
let options = {
enableHighAccuracy: false,
timeout: 5000,
maximumAge: 30000,
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/stores/theme.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-useless-concat */
import { derived } from "svelte/store"
import { appStore } from "./app"
import { builderStore } from "./builder"
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/controllers/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
async function redirect(
ctx: any,
method: "GET" | "POST" | "DELETE",
path: string = "global"
path = "global"
) {
const { devPath } = ctx.params
const queryString = ctx.originalUrl.split("?")[1] || ""
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/controllers/row/ExternalRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export class ExternalRequest<T extends Operation> {
}
// many to one
else {
const thisKey: string = "id"
const thisKey = "id"
// @ts-ignore
const otherKey: string = field.fieldName
for (const relationship of row[key]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/controllers/row/utils/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function getInternalRowId(row: Row, table: Table): string {
export function generateIdForRow(
row: Row | undefined,
table: Table,
isLinked: boolean = false
isLinked = false
): string {
const primary = table.primary
if (!row || !primary) {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/controllers/view/exporters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function escapeCsvString(str: string) {
export function csv(
headers: string[],
rows: Row[],
delimiter: string = ",",
delimiter = ",",
customHeaders: { [key: string]: string } = {}
) {
let csvRows = [getHeaders(headers, customHeaders)]
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/routes/tests/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@ if (descriptions.length) {
// repeat the search many times to check the first row is always the same
let bookmark: string | number | undefined,
hasNextPage: boolean | undefined = true,
rowCount: number = 0
rowCount = 0
do {
const response = await config.api.row.search(
tableOrViewId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class AutomationBuilder extends BaseStepBuilder {
private automationConfig: Automation
private config: TestConfiguration
private triggerOutputs: any
private triggerSet: boolean = false
private triggerSet = false

constructor(
options: { name?: string; appId?: string; config?: TestConfiguration } = {}
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/integrations/microsoftSqlServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ const COLUMN_DEFINITION_METADATA: Record<string, ColumnDefinitionMetadata> = {

class SqlServerIntegration extends Sql implements DatasourcePlus {
private readonly config: MSSQLConfig
private index: number = 0
private index = 0
private client?: sqlServer.ConnectionPool

MASTER_TABLES = [
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/integrations/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const OracleContraintTypes = {

class OracleIntegration extends Sql implements DatasourcePlus {
private readonly config: OracleConfig
private index: number = 1
private index = 1

private static readonly COLUMNS_SQL = `
SELECT
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/integrations/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const SCHEMA: Integration = {
class PostgresIntegration extends Sql implements DatasourcePlus {
private readonly client: Client
private readonly config: PostgresConfig
private index: number = 1
private index = 1
private open: boolean

PRIMARY_KEYS_SQL = () => `
Expand Down Expand Up @@ -252,7 +252,7 @@ class PostgresIntegration extends Sql implements DatasourcePlus {
})
}

async internalQuery(query: SqlQuery, close: boolean = true) {
async internalQuery(query: SqlQuery, close = true) {
if (!this.open) {
await this.openConnection()
}
Expand Down
Loading

0 comments on commit 40d7324

Please sign in to comment.