Skip to content

Commit

Permalink
chore(linting): lint added files
Browse files Browse the repository at this point in the history
  • Loading branch information
evenstensberg committed Feb 19, 2018
1 parent db243b6 commit 6dc12af
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 95 deletions.
5 changes: 1 addition & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
**/__testfixtures__/*
coverage
test
docs
.cz-config.js
/build/**
commitlint.config.js
docs
139 changes: 71 additions & 68 deletions build/changelog-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
* Based on: https://github.com/GoogleChrome/lighthouse/blob/master/build/changelog-generator/
*/
'use strict';
const readFileSync = require('fs').readFileSync;
const resolve = require('path').resolve;
const mainTemplate = readFileSync(resolve(__dirname, 'templates/template.hbs')).toString();
const headerPartial = readFileSync(resolve(__dirname, 'templates/header.hbs')).toString();
const commitPartial = readFileSync(resolve(__dirname, 'templates/commit.hbs')).toString();
"use strict";
const readFileSync = require("fs").readFileSync;
const resolve = require("path").resolve;
const mainTemplate = readFileSync(
resolve(__dirname, "templates/template.hbs")
).toString();
const headerPartial = readFileSync(
resolve(__dirname, "templates/header.hbs")
).toString();
const commitPartial = readFileSync(
resolve(__dirname, "templates/commit.hbs")
).toString();

const pullRequestRegex = /\(#(\d+)\)$/;
const parserOpts = {
headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/,
headerCorrespondence: [
'type',
'scope',
'message',
],
headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/,
headerCorrespondence: ["type", "scope", "message"]
};

process.stderr.write(`
Expand All @@ -28,70 +30,71 @@ process.stderr.write(`
`);

const writerOpts = {
mainTemplate,
headerPartial,
commitPartial,
transform: commit => {
if (typeof commit.hash === 'string') {
commit.hash = commit.hash.substring(0, 7);
}
mainTemplate,
headerPartial,
commitPartial,
transform: commit => {
if (typeof commit.hash === "string") {
commit.hash = commit.hash.substring(0, 7);
}

if (commit.type === 'test') {
commit.type = 'tests';
} else if (commit.type === 'cli') {
commit.type = 'CLI';
} else if (commit.type === 'new_feature') {
commit.type = 'New Features';
}
if (commit.type === "test") {
commit.type = "tests";
} else if (commit.type === "cli") {
commit.type = "CLI";
} else if (commit.type === "new_feature") {
commit.type = "New Features";
}

if (commit.type) {
commit.type = commit.type.replace(/_/g, ' ');
commit.type = commit.type.substring(0, 1).toUpperCase() + commit.type.substring(1);
} else {
commit.type = 'Misc';
}
if (commit.type) {
commit.type = commit.type.replace(/_/g, " ");
commit.type =
commit.type.substring(0, 1).toUpperCase() + commit.type.substring(1);
} else {
commit.type = "Misc";
}

let pullRequestMatch = commit.header.match(pullRequestRegex);
// if header does not provide a PR we try the message
if (!pullRequestMatch && commit.message) {
pullRequestMatch = commit.message.match(pullRequestRegex);
}
let pullRequestMatch = commit.header.match(pullRequestRegex);
// if header does not provide a PR we try the message
if (!pullRequestMatch && commit.message) {
pullRequestMatch = commit.message.match(pullRequestRegex);
}

if (pullRequestMatch) {
commit.header = commit.header.replace(pullRequestMatch[0], '').trim();
if (commit.message) {
commit.message = commit.message.replace(pullRequestMatch[0], '').trim();
}
if (pullRequestMatch) {
commit.header = commit.header.replace(pullRequestMatch[0], "").trim();
if (commit.message) {
commit.message = commit.message.replace(pullRequestMatch[0], "").trim();
}

commit.PR = pullRequestMatch[1];
}
commit.PR = pullRequestMatch[1];
}

return commit;
},
groupBy: 'type',
commitGroupsSort: (a, b) => {
// put new feature on the top
if (a.title === 'New Features') {
return -1;
}
if (b.title === 'New Features') {
return 1;
}
return commit;
},
groupBy: "type",
commitGroupsSort: (a, b) => {
// put new feature on the top
if (a.title === "New Features") {
return -1;
}
if (b.title === "New Features") {
return 1;
}

// put misc on the bottom
if (a.title === 'Misc') {
return 1;
}
if (b.title === 'Misc') {
return -1;
}
// put misc on the bottom
if (a.title === "Misc") {
return 1;
}
if (b.title === "Misc") {
return -1;
}

return a.title.localeCompare(b.title);
},
commitsSort: ['type', 'scope'],
return a.title.localeCompare(b.title);
},
commitsSort: ["type", "scope"]
};

module.exports = {
writerOpts,
parserOpts,
};
writerOpts,
parserOpts
};
45 changes: 22 additions & 23 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

// Config from https://github.com/GoogleChrome/lighthouse/blob/master/commitlint.config.js
'use strict';
// Config from https://github.com/GoogleChrome/lighthouse/blob/master/commitlint.config.js
"use strict";

module.exports = {
extends: ['cz'],
rules: {
'body-leading-blank': [1, 'always'],
'body-tense': [1, 'always', ['present-imperative']],
'footer-leading-blank': [1, 'always'],
'footer-tense': [1, 'always', ['present-imperative']],
'header-max-length': [2, 'always', 80],
'lang': [0, 'always', 'eng'],
'scope-case': [2, 'always', 'lowerCase'],
'scope-empty': [0, 'never'],
'subject-case': [1, 'always', 'lowerCase'],
'subject-empty': [0, 'never'],
'subject-full-stop': [2, 'never', '.'],
'subject-tense': [1, 'always', ['present-imperative']],
'type-case': [2, 'always', 'lowerCase'],
'type-empty': [2, 'never'],
// The scope-enum : defined in the cz-config
// The 'type-enum': defined in the cz-config
},
};
extends: ["cz"],
rules: {
"body-leading-blank": [1, "always"],
"body-tense": [1, "always", ["present-imperative"]],
"footer-leading-blank": [1, "always"],
"footer-tense": [1, "always", ["present-imperative"]],
"header-max-length": [2, "always", 80],
lang: [0, "always", "eng"],
"scope-case": [2, "always", "lowerCase"],
"scope-empty": [0, "never"],
"subject-case": [1, "always", "lowerCase"],
"subject-empty": [0, "never"],
"subject-full-stop": [2, "never", "."],
"subject-tense": [1, "always", ["present-imperative"]],
"type-case": [2, "always", "lowerCase"],
"type-empty": [2, "never"]
// The scope-enum : defined in the cz-config
// The 'type-enum': defined in the cz-config
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"scripts": {
"lint": "eslint \"**/*.js\"",
"f":"prettier-eslint \"build/changelog-generator/index.js\" --write",
"format": "prettier-eslint \"bin/**/*.js\" \"lib/**/*.js\" \"test/**/*.js\" --write",
"lint:codeOnly": "eslint \"{lib,bin}/**/!(__testfixtures__)/*.js\" \"{lib,bin}/**.js\"",
"precommit": "lint-staged",
Expand Down

0 comments on commit 6dc12af

Please sign in to comment.