Skip to content

Commit 9a6c5ba

Browse files
authored
Additional lint checks before publishing (knex#5459)
1 parent 5caf526 commit 9a6c5ba

File tree

15 files changed

+94
-81
lines changed

15 files changed

+94
-81
lines changed

.eslintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ module.exports = {
1010
'plugin:import/warnings',
1111
'prettier',
1212
],
13-
plugins: ['import', 'mocha-no-only'],
13+
plugins: ['prettier', 'import', 'mocha-no-only'],
1414
rules: {
1515
'mocha-no-only/mocha-no-only': ['error'],
1616
'no-unused-vars': [warning, { vars: 'all', args: 'none' }],
1717
'no-console': 'off',
18+
'no-empty': 'off',
1819
'no-var': 2,
1920
'no-debugger': warning,
2021
'prefer-const': warning,

bin/cli.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function invoke() {
218218
.action(async (name) => {
219219
try {
220220
const opts = commander.opts();
221-
const instance = await initKnex(env, opts, true); // Skip config check, we don't really care about client when creating migrations
221+
const instance = await initKnex(env, opts, true); // Skip config check, we don't really care about client when creating migrations
222222
const ext = getMigrationExtension(env, opts);
223223
const configOverrides = { extension: ext };
224224

@@ -233,7 +233,7 @@ function invoke() {
233233
success(color.green(`Created Migration: ${name}`));
234234
})
235235
.catch(exit);
236-
} catch(err) {
236+
} catch (err) {
237237
exit(err);
238238
}
239239
});
@@ -397,7 +397,8 @@ function invoke() {
397397
}
398398

399399
if (opts.timestampFilenamePrefix) {
400-
configOverrides.timestampFilenamePrefix = opts.timestampFilenamePrefix;
400+
configOverrides.timestampFilenamePrefix =
401+
opts.timestampFilenamePrefix;
401402
}
402403

403404
instance.seed
@@ -406,9 +407,9 @@ function invoke() {
406407
success(color.green(`Created seed file: ${name}`));
407408
})
408409
.catch(exit);
409-
} catch(err) {
410+
} catch (err) {
410411
exit(err);
411-
}
412+
}
412413
});
413414

414415
commander

lib/dialects/postgres/schema/pg-compiler.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ class SchemaCompiler_PG extends SchemaCompiler {
120120

121121
refreshMaterializedView(viewName, concurrently = false) {
122122
this.pushQuery({
123-
sql: `refresh materialized view${concurrently ? " concurrently" : ""} ${this.formatter.wrap(viewName)}`,
123+
sql: `refresh materialized view${
124+
concurrently ? ' concurrently' : ''
125+
} ${this.formatter.wrap(viewName)}`,
124126
});
125127
}
126128

lib/knex-builder/Knex.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ knex.ColumnBuilder = {
5050
},
5151
};
5252

53-
knex.TableBuilder = {
53+
knex.TableBuilder = {
5454
extend: function (methodName, fn) {
5555
TableBuilder.extend(methodName, fn);
5656
},

lib/migrations/migrate/MigrationGenerator.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ class MigrationGenerator {
4141

4242
_getNewMigrationName(name) {
4343
if (name[0] === '-') name = name.slice(1);
44-
return yyyymmddhhmmss() + '_' + name + '.' + this.config.extension.split('-')[0];
44+
return (
45+
yyyymmddhhmmss() + '_' + name + '.' + this.config.extension.split('-')[0]
46+
);
4547
}
4648

4749
_getNewMigrationPath(name) {

lib/schema/builder.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ class SchemaBuilder extends EventEmitter {
9797
};
9898
});
9999

100-
101100
SchemaBuilder.extend = (methodName, fn) => {
102-
if (Object.prototype.hasOwnProperty.call(SchemaBuilder.prototype, methodName)) {
101+
if (
102+
Object.prototype.hasOwnProperty.call(SchemaBuilder.prototype, methodName)
103+
) {
103104
throw new Error(
104105
`Can't extend SchemaBuilder with existing method ('${methodName}').`
105106
);

lib/schema/columnbuilder.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ ColumnBuilder.prototype.notNull = ColumnBuilder.prototype.notNullable =
8888
};
8989
});
9090

91-
9291
ColumnBuilder.extend = (methodName, fn) => {
93-
if (Object.prototype.hasOwnProperty.call(ColumnBuilder.prototype, methodName)) {
92+
if (
93+
Object.prototype.hasOwnProperty.call(ColumnBuilder.prototype, methodName)
94+
) {
9495
throw new Error(
9596
`Can't extend ColumnBuilder with existing method ('${methodName}').`
9697
);

lib/schema/tablebuilder.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,10 @@ AlterMethods.dropColumn = AlterMethods.dropColumns = function () {
361361
return this;
362362
};
363363

364-
365364
TableBuilder.extend = (methodName, fn) => {
366-
if (Object.prototype.hasOwnProperty.call(TableBuilder.prototype, methodName)) {
365+
if (
366+
Object.prototype.hasOwnProperty.call(TableBuilder.prototype, methodName)
367+
) {
367368
throw new Error(
368369
`Can't extend TableBuilder with existing method ('${methodName}').`
369370
);

lib/schema/viewbuilder.js

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ const AlterMethods = {
7979

8080
helpers.addQueryContext(ViewBuilder);
8181

82-
8382
ViewBuilder.extend = (methodName, fn) => {
8483
if (Object.prototype.hasOwnProperty.call(ViewBuilder.prototype, methodName)) {
8584
throw new Error(

package.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
"build:ts": "tsc",
1414
"build:gitignore": "node scripts/update_gitignore_for_tsc_output.js run",
1515
"format": "prettier --write \"{lib,bin,scripts,test}/**/*.js\"",
16+
"format:check-difference": "prettier --list-different \"{lib,bin,scripts,test}/**/*.js\"",
1617
"debug:test": "mocha --inspect-brk --exit -t 0 test/all-tests-suite.js",
1718
"debug:tape": "node --inspect-brk test/tape/index.js",
1819
"coveralls": "nyc report --reporter=lcov",
19-
"lint": "eslint \"lib/**/*.js\" \"test/**/*.js\"",
20+
"lint": "eslint \"lib/**/*.js\" \"test/**/*.js\" \"bin/**/*.js\"",
2021
"lint:types": "tsd && dtslint types",
2122
"lint:everything": "npm run lint:types && npm run lint",
2223
"test:unit": "npm run test:unit-only && npm run test:cli",
@@ -57,7 +58,7 @@
5758
"stress:test": "node scripts/stress-test/knex-stress-test.js | grep -A 5 -B 60 -- '- STATS '",
5859
"stress:destroy": "docker-compose -f scripts/stress-test/docker-compose.yml stop",
5960
"prepare": "husky install && npm run clean && npm run build",
60-
"prepublishOnly": "npm run clean && npm run build"
61+
"prepublishOnly": "npm run format:check-difference && npm run lint && npm run clean && npm run build"
6162
},
6263
"dependencies": {
6364
"colorette": "2.0.19",
@@ -114,10 +115,11 @@
114115
"coveralls": "^3.1.1",
115116
"cross-env": "^7.0.3",
116117
"dtslint": "4.2.1",
117-
"eslint": "^8.13.0",
118-
"eslint-config-prettier": "^8.5.0",
118+
"eslint": "^8.32.0",
119+
"eslint-config-prettier": "^8.6.0",
119120
"eslint-plugin-import": "^2.26.0",
120121
"eslint-plugin-mocha-no-only": "^1.1.1",
122+
"eslint-plugin-prettier": "^4.2.1",
121123
"husky": "^8.0.1",
122124
"jake": "^10.8.5",
123125
"JSONStream": "^1.3.5",
@@ -130,7 +132,7 @@
130132
"oracledb": "^5.4.0",
131133
"pg": "^8.8.0",
132134
"pg-query-stream": "^4.2.4",
133-
"prettier": "2.6.2",
135+
"prettier": "2.8.3",
134136
"rimraf": "^3.0.2",
135137
"sinon": "^15.0.1",
136138
"sinon-chai": "^3.7.0",

scripts/clean.js

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
#!/usr/bin/env node
22

3-
const fs = require('fs')
4-
const path = require('path')
5-
const { execSync } = require("child_process");
3+
const fs = require('fs');
4+
const path = require('path');
5+
const { execSync } = require('child_process');
66

77
function main() {
8-
const repoDir = path.dirname(__dirname)
9-
const gitDir = path.join(repoDir, '.git')
10-
const gitDirExists = doesDirectoryExist(gitDir)
8+
const repoDir = path.dirname(__dirname);
9+
const gitDir = path.join(repoDir, '.git');
10+
const gitDirExists = doesDirectoryExist(gitDir);
1111
if (!gitDirExists) {
12-
console.log("No .git directory detected so can not clean 'lib/'. Exiting.")
13-
process.exit(0)
12+
console.log("No .git directory detected so can not clean 'lib/'. Exiting.");
13+
process.exit(0);
1414
}
15-
console.log("Cleaning 'lib/' of outputted files from Typescript compilation ...")
16-
const cmd = 'git clean -f -X lib/'
17-
const output = execSync(cmd, { cwd: repoDir })
18-
console.log(output.toString('utf8'))
19-
console.log('Done')
15+
console.log(
16+
"Cleaning 'lib/' of outputted files from Typescript compilation ..."
17+
);
18+
const cmd = 'git clean -f -X lib/';
19+
const output = execSync(cmd, { cwd: repoDir });
20+
console.log(output.toString('utf8'));
21+
console.log('Done');
2022
}
2123

2224
function doesDirectoryExist(p) {
2325
if (fs.existsSync(p)) {
24-
return fs.lstatSync(p).isDirectory()
26+
return fs.lstatSync(p).isDirectory();
2527
}
26-
return false
28+
return false;
2729
}
2830

29-
main()
31+
main();
+36-32
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env node
22

3-
const path = require('path')
4-
const fs = require('fs')
3+
const path = require('path');
4+
const fs = require('fs');
55

66
// Directory constants
7-
const scriptDirectory = __dirname
8-
const repoDirectory = path.join(scriptDirectory, '..')
9-
const libDirectory = path.join(repoDirectory, 'lib')
7+
const scriptDirectory = __dirname;
8+
const repoDirectory = path.join(scriptDirectory, '..');
9+
const libDirectory = path.join(repoDirectory, 'lib');
1010

1111
const helpText = `
1212
Helper script to update lib/.gitignore for all .js files from .ts files.
@@ -19,7 +19,7 @@ Helper script to update lib/.gitignore for all .js files from .ts files.
1919
2020
NOTES FOR USAGE:
2121
1. This script is tested to work on Ubuntu 18.04 LTS.
22-
`
22+
`;
2323

2424
const gitignoreHeader = `# DO NOT EDIT, GENERATED BY: scripts/update_gitignore_for_tsc_output.js
2525
@@ -30,57 +30,61 @@ const gitignoreHeader = `# DO NOT EDIT, GENERATED BY: scripts/update_gitignore_f
3030
**/*.js.map
3131
3232
# Do not include .js files from .ts files
33-
`
33+
`;
3434

3535
function main(cliCommand) {
3636
if (cliCommand === 'run') {
37-
console.log('Generating lib/.gitignore ...')
37+
console.log('Generating lib/.gitignore ...');
3838

3939
// Find all .ts files in lib/
40-
const directoriesToProcess = [libDirectory]
41-
const tsFiles = []
40+
const directoriesToProcess = [libDirectory];
41+
const tsFiles = [];
4242
while (directoriesToProcess.length > 0) {
43-
const directory = directoriesToProcess.pop()
43+
const directory = directoriesToProcess.pop();
4444
if (!fs.existsSync(directory)) {
45-
throw new Error("Directory doesn't exist:", directory)
45+
throw new Error("Directory doesn't exist:", directory);
4646
}
4747

48-
const files = fs.readdirSync(directory)
48+
const files = fs.readdirSync(directory);
4949
files.forEach((file) => {
50-
const filename = path.join(directory, file)
51-
const stat = fs.lstatSync(filename)
50+
const filename = path.join(directory, file);
51+
const stat = fs.lstatSync(filename);
5252
if (stat.isDirectory()) {
53-
directoriesToProcess.push(filename)
53+
directoriesToProcess.push(filename);
5454
} else if (filename.endsWith('.ts') && !filename.endsWith('.d.ts')) {
55-
tsFiles.push(filename)
56-
console.log('Found .ts file:', filename)
55+
tsFiles.push(filename);
56+
console.log('Found .ts file:', filename);
5757
}
58-
})
58+
});
5959
}
6060

6161
// Get paths of .js files to ignore
6262
const jsFilesToIgnore = tsFiles.map((filepath) => {
6363
// Cuts off `${libDirectory}/`
64-
const relativeTsPath = filepath.slice(libDirectory.length + 1)
64+
const relativeTsPath = filepath.slice(libDirectory.length + 1);
6565
// Swaps .ts for .js file ending
66-
const relativeJsPath = relativeTsPath.slice(0, relativeTsPath.length - 3) + '.js'
66+
const relativeJsPath =
67+
relativeTsPath.slice(0, relativeTsPath.length - 3) + '.js';
6768
// Always use POSIX-style path separators - .gitignore requires it
6869
return relativeJsPath.split(path.sep).join(path.posix.sep);
69-
})
70-
const jsFilesToIgnoreString = jsFilesToIgnore.join('\n')
71-
const libGitignorePath = path.join(libDirectory, '.gitignore')
72-
fs.writeFileSync(libGitignorePath, gitignoreHeader + jsFilesToIgnoreString + '\n')
73-
console.log('DONE')
70+
});
71+
const jsFilesToIgnoreString = jsFilesToIgnore.join('\n');
72+
const libGitignorePath = path.join(libDirectory, '.gitignore');
73+
fs.writeFileSync(
74+
libGitignorePath,
75+
gitignoreHeader + jsFilesToIgnoreString + '\n'
76+
);
77+
console.log('DONE');
7478
} else if (['help', '--help', '-h', undefined].includes(cliCommand)) {
75-
console.log(helpText)
79+
console.log(helpText);
7680
} else {
77-
console.log(`Unsupported command: ${cliCommand}`)
78-
console.log("Try running with 'help' to see supported commands.")
79-
process.exit(1)
81+
console.log(`Unsupported command: ${cliCommand}`);
82+
console.log("Try running with 'help' to see supported commands.");
83+
process.exit(1);
8084
}
8185
}
8286

8387
// Main script logic
84-
const cliCommand = process.argv[2]
88+
const cliCommand = process.argv[2];
8589
// Start the bash app's main function
86-
main(cliCommand)
90+
main(cliCommand);

test/integration/dialects/oracledb.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ describe('Oracle', () => {
6666
const sql = compiler.insert();
6767
expect(sql.sql).to.eql(
6868
'begin execute immediate \'insert into "fakeTable" ("value1", "value2", "value3", "value4") values ' +
69-
'(:1, :2, :3, :4)\' using ?, ?, ?, ?; ' +
70-
'execute immediate \'insert into "fakeTable" ("value1", "value2", "value3", "value4") values ' +
71-
'(:1, DEFAULT, DEFAULT, DEFAULT)\' using ?;end;'
69+
"(:1, :2, :3, :4)' using ?, ?, ?, ?; " +
70+
'execute immediate \'insert into "fakeTable" ("value1", "value2", "value3", "value4") values ' +
71+
"(:1, DEFAULT, DEFAULT, DEFAULT)' using ?;end;"
7272
);
7373
});
7474
});

test/integration2/dialects/oracledb.spec.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,18 @@ describe('Oracledb dialect', () => {
2727

2828
describe('#4869 inserting Buffer', async () => {
2929
it('.toSQL().toNative() generates correct sql and bindings for INSERT of Buffer', async () => {
30-
const b = Buffer.from('hello', 'utf-8')
31-
const query = knex('table1').insert({ value: b })
32-
const queryObj = query.toSQL().toNative()
30+
const b = Buffer.from('hello', 'utf-8');
31+
const query = knex('table1').insert({ value: b });
32+
const queryObj = query.toSQL().toNative();
3333
// Ensure we have two bindings, before fix for #4869 there would only have been one due
3434
// to silent dropping of the Buffer.
35-
expect(queryObj.bindings.length).to.eql(2)
35+
expect(queryObj.bindings.length).to.eql(2);
3636
expect(queryObj).to.eql({
3737
sql: 'insert into "table1" ("value") values (:1) returning "value" into :2',
3838
bindings: [b, { type: 2019, dir: 3003 }],
3939
});
4040
});
4141
});
42-
4342
});
4443
});
4544
});

test/jake-util/helpers/migration-test-helper.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const os = require('os');
44
const fs = require('fs');
5-
const child_process = require("child_process");
5+
const child_process = require('child_process');
66
const rimrafSync = require('rimraf').sync;
77

88
function assertExec(cmd, desc) {
@@ -11,9 +11,7 @@ function assertExec(cmd, desc) {
1111
let stderr = '';
1212
let stdout = '';
1313
const bin = child_process.exec(cmd);
14-
bin.on('error', (msg, code) =>
15-
reject(Error(desc + ' FAIL. ' + stderr))
16-
);
14+
bin.on('error', (msg, code) => reject(Error(desc + ' FAIL. ' + stderr)));
1715
bin.on('cmdEnd', (cmd) => resolve({ cmd, stdout, stderr }));
1816
bin.on('stdout', (data) => (stdout += data.toString()));
1917
bin.on('stderr', (data) => (stderr += data.toString()));

0 commit comments

Comments
 (0)