Skip to content

Commit

Permalink
style: switched from xo to prettier
Browse files Browse the repository at this point in the history
for #296
  • Loading branch information
travi committed May 26, 2023
1 parent abd2a7e commit 6964913
Show file tree
Hide file tree
Showing 15 changed files with 7,057 additions and 19,624 deletions.
93 changes: 58 additions & 35 deletions README.md

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { isUndefined } from 'lodash-es';
import { sync as parser } from 'conventional-commits-parser';
import filter from 'conventional-commits-filter';
import debugFactory from 'debug';
import loadParserConfig from './lib/load-parser-config.js';
import loadReleaseRules from './lib/load-release-rules.js';
import analyzeCommit from './lib/analyze-commit.js';
import compareReleaseTypes from './lib/compare-release-types.js';
import RELEASE_TYPES from './lib/default-release-types.js';
import DEFAULT_RELEASE_RULES from './lib/default-release-rules.js';
import { isUndefined } from "lodash-es";
import { sync as parser } from "conventional-commits-parser";
import filter from "conventional-commits-filter";
import debugFactory from "debug";
import loadParserConfig from "./lib/load-parser-config.js";
import loadReleaseRules from "./lib/load-release-rules.js";
import analyzeCommit from "./lib/analyze-commit.js";
import compareReleaseTypes from "./lib/compare-release-types.js";
import RELEASE_TYPES from "./lib/default-release-types.js";
import DEFAULT_RELEASE_RULES from "./lib/default-release-rules.js";

const debug = debugFactory('semantic-release:commit-analyzer');
const debug = debugFactory("semantic-release:commit-analyzer");

/**
* Determine the type of release to create based on a list of commits.
Expand All @@ -26,42 +26,42 @@ const debug = debugFactory('semantic-release:commit-analyzer');
* @returns {String|null} the type of release to create based on the list of commits or `null` if no release has to be done.
*/
export async function analyzeCommits(pluginConfig, context) {
const {commits, logger} = context;
const { commits, logger } = context;
const releaseRules = loadReleaseRules(pluginConfig, context);
const config = await loadParserConfig(pluginConfig, context);
let releaseType = null;

filter(
commits
.filter(({message, hash}) => {
.filter(({ message, hash }) => {
if (!message.trim()) {
debug('Skip commit %s with empty message', hash);
debug("Skip commit %s with empty message", hash);
return false;
}

return true;
})
.map(({message, ...commitProps}) => ({rawMsg: message, message, ...commitProps, ...parser(message, config)}))
).every(({rawMsg, ...commit}) => {
.map(({ message, ...commitProps }) => ({ rawMsg: message, message, ...commitProps, ...parser(message, config) }))
).every(({ rawMsg, ...commit }) => {
logger.log(`Analyzing commit: %s`, rawMsg);
let commitReleaseType;

// Determine release type based on custom releaseRules
if (releaseRules) {
debug('Analyzing with custom rules');
debug("Analyzing with custom rules");
commitReleaseType = analyzeCommit(releaseRules, commit);
}

// If no custom releaseRules or none matched the commit, try with default releaseRules
if (isUndefined(commitReleaseType)) {
debug('Analyzing with default rules');
debug("Analyzing with default rules");
commitReleaseType = analyzeCommit(DEFAULT_RELEASE_RULES, commit);
}

if (commitReleaseType) {
logger.log('The release type for the commit is %s', commitReleaseType);
logger.log("The release type for the commit is %s", commitReleaseType);
} else {
logger.log('The commit should not trigger a release');
logger.log("The commit should not trigger a release");
}

// Set releaseType if commit's release type is higher
Expand All @@ -76,7 +76,7 @@ export async function analyzeCommits(pluginConfig, context) {

return true;
});
logger.log('Analysis of %s commits complete: %s release', commits.length, releaseType || 'no');
logger.log("Analysis of %s commits complete: %s release", commits.length, releaseType || "no");

return releaseType;
}
22 changes: 11 additions & 11 deletions lib/analyze-commit.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { isMatchWith, isString } from 'lodash-es';
import micromatch from 'micromatch';
import debugFactory from 'debug';
import RELEASE_TYPES from './default-release-types.js';
import compareReleaseTypes from './compare-release-types.js';
import { isMatchWith, isString } from "lodash-es";
import micromatch from "micromatch";
import debugFactory from "debug";
import RELEASE_TYPES from "./default-release-types.js";
import compareReleaseTypes from "./compare-release-types.js";

const debug = debugFactory('semantic-release:commit-analyzer');
const debug = debugFactory("semantic-release:commit-analyzer");
/**
* Find all the rules matching and return the highest release type of the matching rules.
*
Expand All @@ -17,7 +17,7 @@ export default (releaseRules, commit) => {

releaseRules
.filter(
({breaking, revert, release, ...rule}) =>
({ breaking, revert, release, ...rule }) =>
// If the rule is not `breaking` or the commit doesn't have a breaking change note
(!breaking || (commit.notes && commit.notes.length > 0)) &&
// If the rule is not `revert` or the commit is not a revert
Expand All @@ -30,14 +30,14 @@ export default (releaseRules, commit) => {
.every((match) => {
if (compareReleaseTypes(releaseType, match.release)) {
releaseType = match.release;
debug('The rule %o match commit with release type %o', match, releaseType);
debug("The rule %o match commit with release type %o", match, releaseType);
if (releaseType === RELEASE_TYPES[0]) {
debug('Release type %o is the highest possible. Stop analysis.', releaseType);
debug("Release type %o is the highest possible. Stop analysis.", releaseType);
return false;
}
} else {
debug(
'The rule %o match commit with release type %o but the higher release type %o has already been found for this commit',
"The rule %o match commit with release type %o but the higher release type %o has already been found for this commit",
match,
match.release,
releaseType
Expand All @@ -48,4 +48,4 @@ export default (releaseRules, commit) => {
});

return releaseType;
}
};
4 changes: 2 additions & 2 deletions lib/compare-release-types.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import RELEASE_TYPES from './default-release-types.js';
import RELEASE_TYPES from "./default-release-types.js";

/**
* Test if a realease type is of higher level than a given one.
Expand All @@ -8,4 +8,4 @@ import RELEASE_TYPES from './default-release-types.js';
* @return {Boolean} true if `releaseType` is higher than `currentReleaseType`.
*/
export default (currentReleaseType, releaseType) =>
!currentReleaseType || RELEASE_TYPES.indexOf(releaseType) < RELEASE_TYPES.indexOf(currentReleaseType)
!currentReleaseType || RELEASE_TYPES.indexOf(releaseType) < RELEASE_TYPES.indexOf(currentReleaseType);
42 changes: 21 additions & 21 deletions lib/default-release-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@
* @type {Array}
*/
export default [
{ breaking: true, release: 'major' },
{ revert: true, release: 'patch' },
{ breaking: true, release: "major" },
{ revert: true, release: "patch" },
// Angular
{ type: 'feat', release: 'minor' },
{ type: 'fix', release: 'patch' },
{ type: 'perf', release: 'patch' },
{ type: "feat", release: "minor" },
{ type: "fix", release: "patch" },
{ type: "perf", release: "patch" },
// Atom
{ emoji: ':racehorse:', release: 'patch' },
{ emoji: ':bug:', release: 'patch' },
{ emoji: ':penguin:', release: 'patch' },
{ emoji: ':apple:', release: 'patch' },
{ emoji: ':checkered_flag:', release: 'patch' },
{ emoji: ":racehorse:", release: "patch" },
{ emoji: ":bug:", release: "patch" },
{ emoji: ":penguin:", release: "patch" },
{ emoji: ":apple:", release: "patch" },
{ emoji: ":checkered_flag:", release: "patch" },
// Ember
{ tag: 'BUGFIX', release: 'patch' },
{ tag: 'FEATURE', release: 'minor' },
{ tag: 'SECURITY', release: 'patch' },
{ tag: "BUGFIX", release: "patch" },
{ tag: "FEATURE", release: "minor" },
{ tag: "SECURITY", release: "patch" },
// ESLint
{ tag: 'Breaking', release: 'major' },
{ tag: 'Fix', release: 'patch' },
{ tag: 'Update', release: 'minor' },
{ tag: 'New', release: 'minor' },
{ tag: "Breaking", release: "major" },
{ tag: "Fix", release: "patch" },
{ tag: "Update", release: "minor" },
{ tag: "New", release: "minor" },
// Express
{ component: 'perf', release: 'patch' },
{ component: 'deps', release: 'patch' },
{ component: "perf", release: "patch" },
{ component: "deps", release: "patch" },
// JSHint
{ type: 'FEAT', release: 'minor' },
{ type: 'FIX', release: 'patch' },
{ type: "FEAT", release: "minor" },
{ type: "FIX", release: "patch" },
];
2 changes: 1 addition & 1 deletion lib/default-release-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*
* @type {Array}
*/
export default ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'];
export default ["major", "premajor", "minor", "preminor", "patch", "prepatch", "prerelease"];
18 changes: 9 additions & 9 deletions lib/load-parser-config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { promisify } from 'node:util';
import { isPlainObject } from 'lodash-es';
import importFrom from 'import-from';
import conventionalChangelogAngular from 'conventional-changelog-angular';
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { isPlainObject } from "lodash-es";
import importFrom from "import-from";
import conventionalChangelogAngular from "conventional-changelog-angular";

/**
* Load `conventional-changelog-parser` options. Handle presets that return either a `Promise<Array>` or a `Promise<Function>`.
Expand All @@ -29,11 +29,11 @@ export default async ({ preset, config, parserOpts, presetConfig }, { cwd }) =>
loadedConfig = conventionalChangelogAngular;
}

loadedConfig = await (typeof loadedConfig === 'function'
loadedConfig = await (typeof loadedConfig === "function"
? isPlainObject(presetConfig)
? loadedConfig(presetConfig)
: promisify(loadedConfig)()
: loadedConfig);

return {...loadedConfig.parserOpts, ...parserOpts};
}
return { ...loadedConfig.parserOpts, ...parserOpts };
};
14 changes: 7 additions & 7 deletions lib/load-release-rules.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { isUndefined } from 'lodash-es';
import importFrom from 'import-from';
import RELEASE_TYPES from './default-release-types.js';
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { isUndefined } from "lodash-es";
import importFrom from "import-from";
import RELEASE_TYPES from "./default-release-types.js";

/**
* Load and validate the `releaseRules` rules.
Expand All @@ -23,7 +23,7 @@ export default ({ releaseRules }, { cwd }) => {

if (releaseRules) {
loadedReleaseRules =
typeof releaseRules === 'string'
typeof releaseRules === "string"
? importFrom.silent(__dirname, releaseRules) || importFrom(cwd, releaseRules)
: releaseRules;

Expand All @@ -45,4 +45,4 @@ export default ({ releaseRules }, { cwd }) => {
}

return loadedReleaseRules;
}
};
Loading

0 comments on commit 6964913

Please sign in to comment.