Use balena-lint for javascript linting and add javascript type-checking

Change-type: patch
This commit is contained in:
Pagan Gazzard 2020-03-24 17:52:05 +00:00
parent 217cba819a
commit b3b22d6399
10 changed files with 88 additions and 98 deletions

View File

@ -149,9 +149,8 @@ to oclif.
## Programming style
`npm run build` also runs [prettier](https://www.npmjs.com/package/prettier), which automatically
reformats the code (based on configuration in the `node_modules/resin-lint/config/.prettierrc`
file). Beyond that, we have a preference for Javascript promises over callbacks, and for
`npm run build` also runs [balena-lint](https://www.npmjs.com/package/@balena/lint), which automatically
reformats the code. Beyond that, we have a preference for Javascript promises over callbacks, and for
`async/await` over `.then()`.
## Updating upstream dependencies

View File

@ -7,16 +7,18 @@
* We don't `require('semver')` to allow this script to be run as a npm
* 'preinstall' hook, at which point no dependencies have been installed.
*/
function semverGte(v1, v2) {
let v1Array, v2Array; // number[]
try {
const [, major1, minor1, patch1] = /v?(\d+)\.(\d+).(\d+)/.exec(v1);
const [, major2, minor2, patch2] = /v?(\d+)\.(\d+).(\d+)/.exec(v2);
v1Array = [parseInt(major1), parseInt(minor1), parseInt(patch1)];
v2Array = [parseInt(major2), parseInt(minor2), parseInt(patch2)];
} catch (err) {
throw new Error(`Invalid semver versions: '${v1}' or '${v2}'`);
function parseSemver(version) {
const match = /v?(\d+)\.(\d+).(\d+)/.exec(version);
if (match == null) {
throw new Error(`Invalid semver version: ${version}`);
}
const [, major, minor, patch] = match;
return [parseInt(major, 10), parseInt(minor, 10), parseInt(patch, 10)];
}
function semverGte(v1, v2) {
let v1Array = parseSemver(v1);
let v2Array = parseSemver(v2);
for (let i = 0; i < 3; i++) {
if (v1Array[i] < v2Array[i]) {
return false;
@ -27,24 +29,6 @@ function semverGte(v1, v2) {
return true;
}
function _testSemverGet() {
const assert = require('assert').strict;
assert(semverGte('6.4.1', '6.4.1'));
assert(semverGte('6.4.1', 'v6.4.1'));
assert(semverGte('v6.4.1', '6.4.1'));
assert(semverGte('v6.4.1', 'v6.4.1'));
assert(semverGte('6.4.1', '6.4.0'));
assert(semverGte('6.4.1', '6.3.1'));
assert(semverGte('6.4.1', '5.4.1'));
assert(!semverGte('6.4.1', '6.4.2'));
assert(!semverGte('6.4.1', '6.5.1'));
assert(!semverGte('6.4.1', '7.4.1'));
assert(semverGte('v6.4.1', 'v4.0.0'));
assert(!semverGte('v6.4.1', 'v6.9.0'));
assert(!semverGte('v6.4.1', 'v7.0.0'));
}
function checkNpmVersion() {
const execSync = require('child_process').execSync;
const npmVersion = execSync('npm --version')

View File

@ -536,7 +536,7 @@ export function generateTargetState(
// this composition entry (everything else in this
// function comes from the composition which doesn't
// change)
let contract = null;
let contract;
if (name in keyedBuildTasks) {
contract = keyedBuildTasks[name].contract;
}

108
npm-shrinkwrap.json generated
View File

@ -104,6 +104,60 @@
}
}
},
"@balena/lint": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/@balena/lint/-/lint-4.1.1.tgz",
"integrity": "sha512-lvIDG0yXguO53PkY9zF/8O5NLc4YZPv1EgoreSSjAxYEN7ptf+WPr9pAtN8OS1uGQk0/RoTF26IL8flQhInQWg==",
"dev": true,
"requires": {
"@types/depcheck": "^0.6.0",
"@types/glob": "^7.1.1",
"@types/lodash": "^4.14.149",
"@types/node": "^8.10.59",
"@types/optimist": "0.0.29",
"@types/prettier": "^1.18.3",
"coffee-script": "^1.10.0",
"coffeelint": "^1.15.0",
"coffeescope2": "^0.4.5",
"depcheck": "^0.6.7",
"glob": "^7.1.6",
"lodash": "^4.17.15",
"optimist": "^0.6.1",
"prettier": "^1.19.1",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"tslint-no-unused-expression-chai": "^0.1.4",
"typescript": "^3.7.5"
},
"dependencies": {
"@types/node": {
"version": "8.10.59",
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.59.tgz",
"integrity": "sha512-8RkBivJrDCyPpBXhVZcjh7cQxVBSmRk9QM7hOketZzp6Tg79c0N8kkpAIito9bnJ3HCVCHVYz+KHTEbfQNfeVQ==",
"dev": true
},
"coffee-script": {
"version": "1.12.7",
"resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.12.7.tgz",
"integrity": "sha512-fLeEhqwymYat/MpTPUjSKHVYYl0ec2mOyALEMLmzr5i1isuG+6jfI2j2d5oBO3VIzgUXgBVIcOT9uH1TFxBckw==",
"dev": true
},
"glob": {
"version": "7.1.6",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
}
}
},
"@balena/node-web-streams": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/@balena/node-web-streams/-/node-web-streams-0.2.3.tgz",
@ -16142,60 +16196,6 @@
"replacestream": "^4.0.0"
}
},
"resin-lint": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/resin-lint/-/resin-lint-3.3.1.tgz",
"integrity": "sha512-toI24yPozk8u8mqjYJrvIleGIplmHHMFSrvvo/PXUmjAPfIpaIy7mNEQiYL5XAq+TNJBmLxDllc6vPzG1P46Gw==",
"dev": true,
"requires": {
"@types/depcheck": "^0.6.0",
"@types/glob": "^7.1.1",
"@types/lodash": "^4.14.149",
"@types/node": "^8.10.59",
"@types/optimist": "0.0.29",
"@types/prettier": "^1.18.3",
"coffee-script": "^1.10.0",
"coffeelint": "^1.15.0",
"coffeescope2": "^0.4.5",
"depcheck": "^0.6.7",
"glob": "^7.1.6",
"lodash": "^4.17.15",
"optimist": "^0.6.1",
"prettier": "^1.19.1",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"tslint-no-unused-expression-chai": "^0.1.4",
"typescript": "^3.7.5"
},
"dependencies": {
"@types/node": {
"version": "8.10.59",
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.59.tgz",
"integrity": "sha512-8RkBivJrDCyPpBXhVZcjh7cQxVBSmRk9QM7hOketZzp6Tg79c0N8kkpAIito9bnJ3HCVCHVYz+KHTEbfQNfeVQ==",
"dev": true
},
"coffee-script": {
"version": "1.12.7",
"resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.12.7.tgz",
"integrity": "sha512-fLeEhqwymYat/MpTPUjSKHVYYl0ec2mOyALEMLmzr5i1isuG+6jfI2j2d5oBO3VIzgUXgBVIcOT9uH1TFxBckw==",
"dev": true
},
"glob": {
"version": "7.1.6",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
}
}
},
"resin-multibuild": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/resin-multibuild/-/resin-multibuild-4.4.2.tgz",

View File

@ -43,9 +43,9 @@
"postinstall": "patch-package",
"prebuild": "rimraf build/ build-bin/",
"build": "npm run build:src && npm run catch-uncommitted",
"build:src": "npm run prettify && npm run lint && npm run build:fast && npm run build:test && npm run build:doc",
"build:src": "npm run lint && npm run build:fast && npm run build:test && npm run build:doc",
"build:fast": "gulp build && tsc",
"build:test": "tsc -P ./tsconfig.dev.json --noEmit",
"build:test": "tsc -P ./tsconfig.dev.json --noEmit && tsc -P ./tsconfig.js.json --noEmit",
"build:doc": "mkdirp doc/ && ts-node --transpile-only automation/capitanodoc/index.ts > doc/cli.markdown",
"build:standalone": "ts-node --transpile-only automation/run.ts build:standalone",
"build:installer": "ts-node --transpile-only automation/run.ts build:installer",
@ -57,8 +57,7 @@
"catch-uncommitted": "ts-node --transpile-only automation/run.ts catch-uncommitted",
"ci": "npm run test && npm run catch-uncommitted",
"watch": "gulp watch",
"prettify": "prettier --write \"{lib,tests,automation,typings}/**/*.js\" --config ./node_modules/resin-lint/config/.prettierrc",
"lint": "resin-lint lib/ tests/ && resin-lint --typescript --fix automation/ lib/ typings/ tests/",
"lint": "balena-lint lib/ tests/ && balena-lint -e ts -e js --typescript --fix automation/ lib/ typings/ tests/",
"update": "ts-node --transpile-only ./automation/update-module.ts",
"prepublishOnly": "npm run build"
},
@ -93,6 +92,7 @@
}
},
"devDependencies": {
"@balena/lint": "^4.1.1",
"@oclif/config": "^1.14.0",
"@oclif/dev-cli": "1.22.0",
"@oclif/parser": "^3.8.4",
@ -151,7 +151,6 @@
"pkg": "^4.4.2",
"prettier": "^1.19.1",
"publish-release": "^1.6.1",
"resin-lint": "^3.3.1",
"rewire": "^4.0.1",
"simple-git": "^1.131.0",
"sinon": "^7.5.0",

View File

@ -76,7 +76,7 @@ describe('detectEncoding() function', function() {
'node_modules/.bin/prettier',
'node_modules/.bin/coffeelint',
'node_modules/.bin/tsc',
'node_modules/.bin/resin-lint',
'node_modules/.bin/balena-lint',
'node_modules/.bin/balena-preload',
'node_modules/.bin/catch-uncommitted',
];

View File

@ -1,9 +1,9 @@
{
"extends": "./tsconfig.json",
"include": [
"./automation/**/*.ts",
"./lib/**/*.ts",
"./tests/**/*.ts",
"./typings/**/*.ts"
"./automation/**/*",
"./lib/**/*",
"./tests/**/*",
"./typings/**/*"
]
}

7
tsconfig.js.json Normal file
View File

@ -0,0 +1,7 @@
{
"extends": "./tsconfig.dev.json",
"compilerOptions": {
"noImplicitAny": false,
"checkJs": true
}
}

View File

@ -17,9 +17,10 @@
"./node_modules/etcher-sdk/typings",
"./typings"
],
"preserveSymlinks": true
"preserveSymlinks": true,
"allowJs": true
},
"include": [
"./lib/**/*.ts"
"./lib/**/*"
]
}

View File

@ -1,5 +1,5 @@
{
"extends": "./node_modules/resin-lint/config/tslint-prettier.json",
"extends": "./node_modules/@balena/lint/config/tslint-prettier.json",
"rules": {
"ignoreDefinitionFiles": false
}