Skip to content

Commit

Permalink
style: Enable some linter rules (typeorm#10592)
Browse files Browse the repository at this point in the history
* style: 🚨 enable some linter rules

* Revert "style: 🚨 enable some linter rules"

This reverts commit 239fa2d.

* revert: ⏪ revert role "prefer-const"

* revert: ⏪ enable linter warnings

* style: 🚨 enable rule "no-extra-boolean-cast"

* revert: ⏪ disable rule "no-empty"

* style: 🚨 add linter rule "no-useless-escape"

* style: 🚨 add linter rule "no-unsafe-optional-chaining"
  • Loading branch information
kusigit authored Jan 26, 2024
1 parent 62f574b commit e224819
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 25 deletions.
4 changes: 0 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@
"@typescript-eslint/triple-slash-reference": "warn",
"no-async-promise-executor": "warn",
"no-control-regex": "warn",
"no-debugger": "warn",
"no-empty": "warn",
"no-extra-boolean-cast": "warn",
"no-extra-semi": "warn",
"no-prototype-builtins": "warn",
"no-regex-spaces": "warn",
"no-unsafe-optional-chaining": "warn",
"no-useless-escape": "warn",
"prefer-const": "warn",
"prefer-rest-params": "warn",
"prefer-spread": "warn"
Expand Down
6 changes: 3 additions & 3 deletions src/driver/cockroachdb/CockroachQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3348,10 +3348,10 @@ export class CockroachQueryRunner
} else {
tableColumn.default = dbColumn[
"column_default"
].replace(/:::[\w\s\[\]\"]+/g, "")
].replace(/:::[\w\s[\]"]+/g, "")
tableColumn.default =
tableColumn.default.replace(
/^(-?[\d\.]+)$/,
/^(-?[\d.]+)$/,
"($1)",
)

Expand Down Expand Up @@ -3744,7 +3744,7 @@ export class CockroachQueryRunner
protected async getVersion(): Promise<string> {
const result = await this.query(`SELECT version()`)
return result[0]["version"].replace(
/^CockroachDB CCL v([\d\.]+) .*$/,
/^CockroachDB CCL v([\d.]+) .*$/,
"$1",
)
}
Expand Down
6 changes: 3 additions & 3 deletions src/driver/postgres/PostgresDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ export class PostgresDriver implements Driver {
}[]
}
const versionString = results.rows[0].version.replace(
/^PostgreSQL ([\d\.]+) .*$/,
/^PostgreSQL ([\d.]+) .*$/,
"$1",
)
this.version = versionString
Expand Down Expand Up @@ -745,15 +745,15 @@ export class PostgresDriver implements Driver {
} else if (columnMetadata.type === "simple-json") {
value = DateUtils.stringToSimpleJson(value)
} else if (columnMetadata.type === "cube") {
value = value.replace(/[\(\)\s]+/g, "") // remove whitespace
value = value.replace(/[()\s]+/g, "") // remove whitespace
if (columnMetadata.isArray) {
/**
* Strips these groups from `{"1,2,3","",NULL}`:
* 1. ["1,2,3", undefined] <- cube of arity 3
* 2. ["", undefined] <- cube of arity 0
* 3. [undefined, "NULL"] <- NULL
*/
const regexp = /(?:\"((?:[\d\s\.,])*)\")|(?:(NULL))/g
const regexp = /(?:"((?:[\d\s.,])*)")|(?:(NULL))/g
const unparsedArrayString = value

value = []
Expand Down
4 changes: 2 additions & 2 deletions src/driver/postgres/PostgresQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3775,7 +3775,7 @@ export class PostgresQueryRunner
} else {
tableColumn.default = dbColumn[
"column_default"
].replace(/::[\w\s.\[\]\-"]+/g, "")
].replace(/::[\w\s.[\]\-"]+/g, "")
tableColumn.default =
tableColumn.default.replace(
/^(-?\d+)$/,
Expand Down Expand Up @@ -4148,7 +4148,7 @@ export class PostgresQueryRunner
*/
protected async getVersion(): Promise<string> {
const result = await this.query(`SELECT version()`)
return result[0]["version"].replace(/^PostgreSQL ([\d\.]+) .*$/, "$1")
return result[0]["version"].replace(/^PostgreSQL ([\d.]+) .*$/, "$1")
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ export abstract class AbstractSqliteQueryRunner
const fullType = tableColumn.type
let dataType = fullType.substr(0, pos)
if (
!!this.driver.withLengthColumnTypes.find(
this.driver.withLengthColumnTypes.find(
(col) => col === dataType,
)
) {
Expand All @@ -1484,7 +1484,7 @@ export abstract class AbstractSqliteQueryRunner
}
}
if (
!!this.driver.withPrecisionColumnTypes.find(
this.driver.withPrecisionColumnTypes.find(
(col) => col === dataType,
)
) {
Expand All @@ -1496,7 +1496,7 @@ export abstract class AbstractSqliteQueryRunner
tableColumn.precision = +matches[1]
}
if (
!!this.driver.withScaleColumnTypes.find(
this.driver.withScaleColumnTypes.find(
(col) => col === dataType,
)
) {
Expand Down
2 changes: 1 addition & 1 deletion src/query-builder/InsertQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ export class InsertQueryBuilder<

if (Array.isArray(overwrite)) {
updatePart.push(
...overwrite?.map(
...overwrite.map(
(column) =>
`${this.escape(
column,
Expand Down
6 changes: 3 additions & 3 deletions src/query-builder/QueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,15 +767,15 @@ export abstract class QueryBuilder<Entity extends ObjectLiteral> {
statement = statement.replace(
new RegExp(
// Avoid a lookbehind here since it's not well supported
`([ =\(]|^.{0})` + // any of ' =(' or start of line
`([ =(]|^.{0})` + // any of ' =(' or start of line
// followed by our prefix, e.g. 'tablename.' or ''
`${
replaceAliasNamePrefixes
? "(" + replaceAliasNamePrefixes + ")"
: ""
}([^ =\(\)\,]+)` + // a possible property name: sequence of anything but ' =(),'
}([^ =(),]+)` + // a possible property name: sequence of anything but ' =(),'
// terminated by ' =),' or end of line
`(?=[ =\)\,]|.{0}$)`,
`(?=[ =),]|.{0}$)`,
"gm",
),
(...matches) => {
Expand Down
2 changes: 1 addition & 1 deletion src/util/PathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ export function filepathToName(filepath: string): string {
* Cross platform isAbsolute
*/
export function isAbsolute(filepath: string): boolean {
return !!filepath.match(/^(?:[a-z]:|[\\]|[\/])/i)
return !!filepath.match(/^(?:[a-z]:|[\\]|[/])/i)
}
2 changes: 1 addition & 1 deletion test/functional/cube/postgres/cube-postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe("cube-postgres", () => {
// to be working on Postgres version >=10.6.
const [{ version }] = await connection.query("SELECT version()")
const semverArray = version
.replace(/^PostgreSQL ([\d\.]+) .*$/, "$1")
.replace(/^PostgreSQL ([\d.]+) .*$/, "$1")
.split(".")
.map(Number)
if (!(semverArray[0] >= 10 && semverArray[1] >= 6)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe("multi-database > basic-functionality", () => {
const expectedMainPath = path.join(
tempPath,
(connections[0].options.database as string).match(
/^.*[\\|\/](?<filename>[^\\|\/]+)$/,
/^.*[\\|/](?<filename>[^\\|/]+)$/,
)!.groups!["filename"],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ describe("repository > find options > comment", () => {
const lines = logs.toString().split("\n")
const lastLine = lines[lines.length - 2] // last line is blank after newline
// remove timestamp and prefix
const sql = lastLine.replace(/^.*\[QUERY\]\: /, "")
const sql = lastLine.replace(/^.*\[QUERY\]: /, "")
expect(sql).to.match(/^\/\* This is a query comment. \*\//)
}),
))
Expand Down
1 change: 0 additions & 1 deletion test/github-issues/10054/issue-10054.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe("github issues > #10054 Nested 'Or' Condition/Operation Support in Repo
it("should find person where name starts with foo or equal to jane", async () => {
await Promise.all(
dataSources.map(async (dataSource) => {
debugger
const foo = new Person()
foo.name = "Foo"
foo.age = null
Expand Down
2 changes: 1 addition & 1 deletion test/github-issues/9318/issue-9318.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("github issues > #9318 Change version query from SHOW server_version to
connection.driver as PostgresDriver
const result = await connection.query("SELECT VERSION()")
const dbVersion = result[0]["version"].replace(
/^PostgreSQL ([\d\.]+) .*$/,
/^PostgreSQL ([\d.]+) .*$/,
"$1",
)
const versionGreaterOfEqualTo12 = VersionUtils.isGreaterOrEqual(
Expand Down

0 comments on commit e224819

Please sign in to comment.