Skip to content

Commit

Permalink
Prettier config & prettify everything; change last-coverage-summary.j…
Browse files Browse the repository at this point in the history
…son identation level to match prettier default
  • Loading branch information
m-khvoinitsky committed Jan 7, 2023
1 parent e1eae63 commit 75c3564
Show file tree
Hide file tree
Showing 76 changed files with 5,248 additions and 4,360 deletions.
441 changes: 186 additions & 255 deletions .eslintrc.js

Large diffs are not rendered by default.

118 changes: 64 additions & 54 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,55 +1,65 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-added-large-files
- repo: https://github.com/jumanjihouse/pre-commit-hooks.git
rev: 2.1.5
hooks:
- id: shellcheck
args: ['--shell=bash', '--color=always', '--external-sources']
additional_dependencies: []
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.0.0-beta.0
hooks:
- id: eslint
- repo: local
hooks:
- id: tests
name: Mocha tests
language: system
entry: npm test
always_run: true
pass_filenames: false
require_serial: true
- repo: local
hooks:
- id: coverage
name: Ensure that coverage hasn't decreased per-file
language: system
entry: ./check-coverage last-coverage-summary.json
always_run: true
pass_filenames: false
require_serial: true
- repo: local
hooks:
- id: svelte-check
name: Svelte check
language: system
entry: npx svelte-check --fail-on-warnings
always_run: true
pass_filenames: false
require_serial: true
- repo: local
hooks:
- id: rollup
name: Rollup dry run
language: system
entry: sh -c 'ADDON_DIST_DIR="$(mktemp -d)"; export ADDON_DIST_DIR; npm run build; EXITCODE=$?; rm -r "${ADDON_DIST_DIR}"; exit "${EXITCODE}"'
always_run: true
pass_filenames: false
require_serial: true
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-added-large-files
- repo: https://github.com/jumanjihouse/pre-commit-hooks.git
rev: 2.1.5
hooks:
- id: shellcheck
args: ['--shell=bash', '--color=always', '--external-sources']
additional_dependencies: []
- repo: local
hooks:
- id: prettier
name: prettier
entry: npx prettier --write --list-different --ignore-unknown
language: system
pass_filenames: true
types: [text]
args: []
require_serial: false
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.0.0-beta.0
hooks:
- id: eslint
- repo: local
hooks:
- id: tests
name: Mocha tests
language: system
entry: npm test
always_run: true
pass_filenames: false
require_serial: true
- repo: local
hooks:
- id: coverage
name: Ensure that coverage hasn't decreased per-file
language: system
entry: ./check-coverage last-coverage-summary.json
always_run: true
pass_filenames: false
require_serial: true
- repo: local
hooks:
- id: svelte-check
name: Svelte check
language: system
entry: npx svelte-check --fail-on-warnings
always_run: true
pass_filenames: false
require_serial: true
- repo: local
hooks:
- id: rollup
name: Rollup dry run
language: system
entry: sh -c 'ADDON_DIST_DIR="$(mktemp -d)"; export ADDON_DIST_DIR; npm run build; EXITCODE=$?; rm -r "${ADDON_DIST_DIR}"; exit "${EXITCODE}"'
always_run: true
pass_filenames: false
require_serial: true
2 changes: 2 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trailingComma: all
singleQuote: true
48 changes: 28 additions & 20 deletions check-coverage
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,48 @@ const fs = require('fs');
const { execFileSync } = require('child_process');

const coverage_file = process.argv[2];
const new_coverage = JSON.parse(fs.readFileSync(coverage_file, { encoding: 'utf8' }));
const new_coverage = JSON.parse(
fs.readFileSync(coverage_file, { encoding: 'utf8' }),
);

let prev_coverage_ref;
if (Object.prototype.hasOwnProperty.call(process.env, 'PRE_COMMIT_FROM_REF')) {
prev_coverage_ref = process.env.PRE_COMMIT_FROM_REF;
prev_coverage_ref = process.env.PRE_COMMIT_FROM_REF;
} else {
prev_coverage_ref = 'HEAD';
prev_coverage_ref = 'HEAD';
}
let prev_coverage_text;
try {
prev_coverage_text = execFileSync('git', ['show', `${prev_coverage_ref}:${coverage_file}`], { encoding: 'utf8' });
prev_coverage_text = execFileSync(
'git',
['show', `${prev_coverage_ref}:${coverage_file}`],
{ encoding: 'utf8' },
);
} catch (e) {
console.log('Previous coverage is not found');
prev_coverage_text = '{}';
console.log('Previous coverage is not found');
prev_coverage_text = '{}';
}
const prev_coverage = JSON.parse(prev_coverage_text);

let decreased = false;
Object.keys(new_coverage).forEach((f) => {
if (f === 'total') {
return;
}
Object.keys(new_coverage[f]).sort().forEach((what) => {
let prev_val = 0;
if (f in prev_coverage) {
prev_val = parseFloat(prev_coverage[f][what].pct);
}
const new_val = parseFloat(new_coverage[f][what].pct);
if (new_val < prev_val) {
decreased = true;
console.log(`${f} ${what}: ${prev_val} -> ${new_val}`);
}
if (f === 'total') {
return;
}
Object.keys(new_coverage[f])
.sort()
.forEach((what) => {
let prev_val = 0;
if (f in prev_coverage) {
prev_val = parseFloat(prev_coverage[f][what].pct);
}
const new_val = parseFloat(new_coverage[f][what].pct);
if (new_val < prev_val) {
decreased = true;
console.log(`${f} ${what}: ${prev_val} -> ${new_val}`);
}
});
});
if (decreased) {
process.exit(2);
process.exit(2);
}
34 changes: 15 additions & 19 deletions coverage-relative-json-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,23 @@ const { writeFileSync } = require('fs');
const { relative } = require('path');

class RelativeJsonSummaryReport extends ReportBase {
constructor() {
super();
constructor() {
super();

this.data = {};
}
this.data = {};
}

onDetail(node) {
this.data[
relative(
process.cwd(),
node.getFileCoverage().path,
)
] = node.getCoverageSummary();
}
onDetail(node) {
this.data[relative(process.cwd(), node.getFileCoverage().path)] =
node.getCoverageSummary();
}

onEnd() {
writeFileSync(
'last-coverage-summary.json',
`${JSON.stringify(this.data, null, 4)}\n`,
{ encoding: 'utf8' },
);
}
onEnd() {
writeFileSync(
'last-coverage-summary.json',
`${JSON.stringify(this.data, null, 2)}\n`,
{ encoding: 'utf8' },
);
}
}
module.exports = RelativeJsonSummaryReport;
Loading

0 comments on commit 75c3564

Please sign in to comment.