diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 679c678b..ad717e2b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/automation/check-npm-version.js b/automation/check-npm-version.js index 287124e9..d4bb5d12 100644 --- a/automation/check-npm-version.js +++ b/automation/check-npm-version.js @@ -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') diff --git a/lib/utils/device/deploy.ts b/lib/utils/device/deploy.ts index c99df4fa..1d5e9a1a 100644 --- a/lib/utils/device/deploy.ts +++ b/lib/utils/device/deploy.ts @@ -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; } diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 65010680..f9697f34 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -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", diff --git a/package.json b/package.json index 0704ab61..885f1a2b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/utils/eol-conversion.spec.ts b/tests/utils/eol-conversion.spec.ts index a2b7400d..c0ab6065 100644 --- a/tests/utils/eol-conversion.spec.ts +++ b/tests/utils/eol-conversion.spec.ts @@ -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', ]; diff --git a/tsconfig.dev.json b/tsconfig.dev.json index 631e5605..6a172666 100644 --- a/tsconfig.dev.json +++ b/tsconfig.dev.json @@ -1,9 +1,9 @@ { "extends": "./tsconfig.json", "include": [ - "./automation/**/*.ts", - "./lib/**/*.ts", - "./tests/**/*.ts", - "./typings/**/*.ts" + "./automation/**/*", + "./lib/**/*", + "./tests/**/*", + "./typings/**/*" ] } diff --git a/tsconfig.js.json b/tsconfig.js.json new file mode 100644 index 00000000..5967fb2a --- /dev/null +++ b/tsconfig.js.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.dev.json", + "compilerOptions": { + "noImplicitAny": false, + "checkJs": true + } +} diff --git a/tsconfig.json b/tsconfig.json index aae0aef4..14d1ac1b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,9 +17,10 @@ "./node_modules/etcher-sdk/typings", "./typings" ], - "preserveSymlinks": true + "preserveSymlinks": true, + "allowJs": true }, "include": [ - "./lib/**/*.ts" + "./lib/**/*" ] } diff --git a/tslint.json b/tslint.json index 0be8c926..5923f444 100644 --- a/tslint.json +++ b/tslint.json @@ -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 }