Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
integrate prettier formatting with eslint; update formatting a little…
… bit
  • Loading branch information
trentm committed Sep 25, 2020
1 parent 9dfbfd4 commit 8f9830f
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 53 deletions.
7 changes: 5 additions & 2 deletions .eslintrc.json
@@ -1,7 +1,10 @@
{
"plugins": [],
"plugins": [
"prettier"
],
"extends": [
"eslint:recommended"
"eslint:recommended",
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaVersion": 6,
Expand Down
33 changes: 18 additions & 15 deletions 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.
Expand Down
22 changes: 10 additions & 12 deletions lib/cli/do_issue/do_create.js
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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);
});
}
},

Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/do_issue/do_edit.js
Expand Up @@ -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;
Expand Down
15 changes: 12 additions & 3 deletions lib/cli/do_issue/index.js
Expand Up @@ -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);
Expand Down
30 changes: 18 additions & 12 deletions lib/cli/do_version/do_delete.js
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion lib/common.js
Expand Up @@ -600,7 +600,6 @@ function readStdin(cb) {
});
}


// ---- exports

module.exports = {
Expand Down
17 changes: 10 additions & 7 deletions lib/jirashapi.js
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
{
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions package.json
Expand Up @@ -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",
Expand All @@ -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"
}
}

0 comments on commit 8f9830f

Please sign in to comment.