diff --git a/.eslintrc.json b/.eslintrc.json index 8bac833..45ec202 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,10 @@ { - "plugins": [], + "plugins": [ + "prettier" + ], "extends": [ - "eslint:recommended" + "eslint:recommended", + "plugin:prettier/recommended" ], "parserOptions": { "ecmaVersion": 6, diff --git a/Makefile b/Makefile index 36581bf..55cab3b 100644 --- a/Makefile +++ b/Makefile @@ -1,35 +1,38 @@ -# -# Copyright (c) 2017, Joyent, Inc. -# -ESLINT = ./node_modules/.bin/eslint -JSFILES := bin/jirash $(shell find lib -name '*.js') - -all $(ESLINT): +.PHONY: all +all: npm install .PHONY: clean clean: + rm -rf jirash-*.tgz + +.PHONY: distclean +distclean: clean rm -rf node_modules +.PHONY: lint +lint: + npm run lint + +.PHONY: fmt +fmt: + npm run fmt + .PHONY: check check:: check-version check-eslint @echo "Check ok." +.PHONY: check-eslint +check-eslint: + npm run check + # Ensure CHANGES.md and package.json have the same version. .PHONY: check-version check-version: @echo version is: $(shell cat package.json | json version) [[ `cat package.json | json version` == `grep '^## ' CHANGES.md | head -2 | tail -1 | awk '{print $$2}'` ]] -.PHONY: check-eslint -check-eslint: | $(ESLINT) - $(ESLINT) $(JSFILES) - -.PHONY: fmt -fmt: | $(ESLINT) - $(ESLINT) --fix $(JSFILES) - .PHONY: cutarelease cutarelease: check-version [[ -z `git status --short` ]] # If this fails, the working dir is dirty. diff --git a/lib/cli/do_issue/do_create.js b/lib/cli/do_issue/do_create.js index dfe4a6e..6b1b823 100644 --- a/lib/cli/do_issue/do_create.js +++ b/lib/cli/do_issue/do_create.js @@ -71,10 +71,7 @@ function parseIssueForm(text) { line ); } - var field = line - .slice(0, idx) - .trim() - .toLowerCase(); + var field = line.slice(0, idx).trim().toLowerCase(); var value = line.slice(idx + 1).trim(); if (field === 'description') { parsedFields.description = []; @@ -397,12 +394,13 @@ function do_create(subcmd, opts, args, cb) { next(); }); } else { - fs.readFile(opts.f, 'utf8', - function doneReading(readErr, text) { - ctx.fileText = text; - next(readErr); - } - ); + fs.readFile(opts.f, 'utf8', function doneReading( + readErr, + text + ) { + ctx.fileText = text; + next(readErr); + }); } }, @@ -512,8 +510,8 @@ function do_create(subcmd, opts, args, cb) { cb(err); } else if (context.editFilename && !opts.f) { /* - * Clean up the temporary edit filename on success. - */ + * Clean up the temporary edit filename on success. + */ log.trace( {editFilename: context.editFilename}, 'unlink editFilename' diff --git a/lib/cli/do_issue/do_edit.js b/lib/cli/do_issue/do_edit.js index 79f9bf3..85e7ad6 100644 --- a/lib/cli/do_issue/do_edit.js +++ b/lib/cli/do_issue/do_edit.js @@ -19,7 +19,7 @@ function do_edit(subcmd, opts, args, cb) { var key = args[0]; var issueData; try { - issueData = {'update': JSON.parse(args[1])}; + issueData = {update: JSON.parse(args[1])}; } catch (parseErr) { cb(new UsageError('could not parse EDIT-JSON: ' + parseErr.message)); return; diff --git a/lib/cli/do_issue/index.js b/lib/cli/do_issue/index.js index 889cf37..6d15c9e 100644 --- a/lib/cli/do_issue/index.js +++ b/lib/cli/do_issue/index.js @@ -14,12 +14,21 @@ function IssueCli(top) { Cmdln.call(this, { name: top.name + ' issue', desc: ['Search, get, edit, comment on and create JIRA issues.'].join( - '\n'), + '\n' + ), helpOpts: { minHelpCol: 24 /* line up with option help */ }, - helpSubcmds: ['help', 'list', 'get', 'create', 'link', 'linktypes', - 'edit', 'comment'] + helpSubcmds: [ + 'help', + 'list', + 'get', + 'create', + 'link', + 'linktypes', + 'edit', + 'comment' + ] }); } util.inherits(IssueCli, Cmdln); diff --git a/lib/cli/do_version/do_delete.js b/lib/cli/do_version/do_delete.js index eb5a7ca..65c7a31 100644 --- a/lib/cli/do_version/do_delete.js +++ b/lib/cli/do_version/do_delete.js @@ -56,19 +56,25 @@ function do_delete(subcmd, opts, args, cb) { return; } - common.promptYesNo({ - msg: format('Delete version %d (%s)? [y/N] ', - ctx.ver.id, ctx.verDesc), - default: 'n' - }, function response(answer) { - if (answer === 'y') { - next(); - } else if (answer === 'n') { - next(true); - } else { - next(new VError('cancelled')); + common.promptYesNo( + { + msg: format( + 'Delete version %d (%s)? [y/N] ', + ctx.ver.id, + ctx.verDesc + ), + default: 'n' + }, + function response(answer) { + if (answer === 'y') { + next(); + } else if (answer === 'n') { + next(true); + } else { + next(new VError('cancelled')); + } } - }); + ); }, function deleteIt(ctx, next) { diff --git a/lib/common.js b/lib/common.js index 86b08cb..6ae058a 100644 --- a/lib/common.js +++ b/lib/common.js @@ -600,7 +600,6 @@ function readStdin(cb) { }); } - // ---- exports module.exports = { diff --git a/lib/jirashapi.js b/lib/jirashapi.js index 1a70d03..20ac30f 100644 --- a/lib/jirashapi.js +++ b/lib/jirashapi.js @@ -31,7 +31,7 @@ function _stripNullOrUndefined(obj) { function has(obj, key) { assert.string(key, 'key'); - return (Object.prototype.hasOwnProperty.call(obj, key)); + return Object.prototype.hasOwnProperty.call(obj, key); } // ---- Jirash API class @@ -461,8 +461,10 @@ JirashApi.prototype.editIssue = function editIssue(opts, cb) { function putIt(ctx, next) { ctx.jiraClient.put( { - path: format('/rest/api/2/issue/%s', - opts.issueIdOrKey) + path: format( + '/rest/api/2/issue/%s', + opts.issueIdOrKey + ) }, opts.issueData, function onRes(err, _req, _res, body) { @@ -498,7 +500,7 @@ JirashApi.prototype.commentIssue = function commentIssue(opts, cb) { api: this }; - var post = {'body': opts.issueComment}; + var post = {body: opts.issueComment}; vasync.pipeline( { @@ -509,8 +511,10 @@ JirashApi.prototype.commentIssue = function commentIssue(opts, cb) { function putIt(ctx, next) { ctx.jiraClient.post( { - path: format('/rest/api/2/issue/%s/comment', - opts.issueIdOrKey) + path: format( + '/rest/api/2/issue/%s/comment', + opts.issueIdOrKey + ) }, post, function onRes(err, _req, _res, body) { @@ -926,7 +930,6 @@ JirashApi.prototype.search = function search(opts, cb) { ); }; - /* * Paging search of issues * https://docs.atlassian.com/jira/REST/7.4.2/#api/2/search-search diff --git a/package-lock.json b/package-lock.json index f04eb47..5740849 100644 --- a/package-lock.json +++ b/package-lock.json @@ -396,6 +396,24 @@ } } }, + "eslint-config-prettier": { + "version": "6.12.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-6.12.0.tgz", + "integrity": "sha512-9jWPlFlgNwRUYVoujvWTQ1aMO8o6648r+K7qU7K5Jmkbyqav1fuEZC0COYpGBxyiAJb65Ra9hrmFx19xRGwXWw==", + "dev": true, + "requires": { + "get-stdin": "^6.0.0" + } + }, + "eslint-plugin-prettier": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.4.tgz", + "integrity": "sha512-jZDa8z76klRqo+TdGDTFJSavwbnWK2ZpqGKNZ+VvweMW516pDUMmQ2koXvxEE4JhzNvTv+radye/bWGBmA6jmg==", + "dev": true, + "requires": { + "prettier-linter-helpers": "^1.0.0" + } + }, "eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -495,6 +513,12 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, + "fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "dev": true + }, "fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -580,6 +604,12 @@ "resolved": "https://registry.npmjs.org/fuzzyset.js/-/fuzzyset.js-0.0.1.tgz", "integrity": "sha1-l54i+UUbSzjwUfeTfJGdusxpKVg=" }, + "get-stdin": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", + "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", + "dev": true + }, "glob": { "version": "6.0.4", "resolved": "https://registry.npmjs.org/glob/-/glob-6.0.4.tgz", @@ -897,6 +927,15 @@ "integrity": "sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==", "dev": true }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "requires": { + "fast-diff": "^1.1.2" + } + }, "progress": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", diff --git a/package.json b/package.json index a170d23..4bb748b 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,11 @@ "bin", "etc" ], + "scripts": { + "check": "eslint lib bin/jirash", + "lint": "eslint --rule 'prettier/prettier: off' lib bin/jirash", + "fmt": "eslint --fix lib bin/jirash" + }, "dependencies": { "assert-plus": "^1.0.0", "bunyan": "^1.8.12", @@ -41,6 +46,8 @@ }, "devDependencies": { "eslint": "^7.9.0", + "eslint-config-prettier": "^6.11.0", + "eslint-plugin-prettier": "^3.1.4", "prettier": "^2.1.2" } }