Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a readiness report and threshold #134

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion es5/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var buildVersion = JSON.parse(packageConfig).version;
_commander2.default.version(buildVersion)
// default cli behaviour will be an interactive walkthrough each error, with suggestions,
// options to replace etc.
.option('-r, --report', 'Outputs a full report which details the unique spelling errors found.').option('-n, --ignore-numbers', 'Ignores numbers.').option('--en-us', 'American English dictionary.').option('--en-gb', 'British English dictionary.').option('--en-au', 'Australian English dictionary.').option('--es-es', 'Spanish dictionary.').option('-d, --dictionary [file]', 'specify a custom dictionary file - it should not include the file extension and will load .dic and .aiff.').option('-a, --ignore-acronyms', 'Ignores acronyms.').option('-x, --no-suggestions', 'Do not suggest words (can be slow)').option('-t, --target-relative', 'Uses ".spelling" files relative to the target.').usage("[options] source-file source-file").parse(process.argv);
.option('-r, --report', 'Outputs a full report which details the unique spelling errors found.').option('-n, --ignore-numbers', 'Ignores numbers.').option('--en-us', 'American English dictionary.').option('--en-gb', 'British English dictionary.').option('--en-au', 'Australian English dictionary.').option('--es-es', 'Spanish dictionary.').option('-d, --dictionary [file]', 'specify a custom dictionary file - it should not include the file extension and will load .dic and .aiff.').option('-a, --ignore-acronyms', 'Ignores acronyms.').option('-x, --no-suggestions', 'Do not suggest words (can be slow)').option('-t, --target-relative', 'Uses ".spelling" files relative to the target.').option('-y, --readiness [100]', 'Allows for a percentage readiness setting - default is set to 100 for no errors allowed').usage("[options] source-file source-file").parse(process.argv);

var language = void 0;
if (_commander2.default.enUs) {
Expand Down Expand Up @@ -94,5 +94,8 @@ if (!_commander2.default.args.length) {
}
}, function (e, results) {
console.log((0, _reportGenerator.generateSummaryReport)(results));
if (_commander2.default.readiness) {
console.log((0, _reportGenerator.generateReadinessReport)(_commander2.default.readiness, results));
}
});
}
54 changes: 54 additions & 0 deletions es5/report-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports.__esModule = true;
exports.generateSummaryReport = generateSummaryReport;
exports.generateReadinessReport = generateReadinessReport;
exports.generateFileReport = generateFileReport;

var _chalk = require('chalk');
Expand All @@ -14,6 +15,8 @@ var _context2 = _interopRequireDefault(_context);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

// Generates a report that summarises the spelling errors found across multiple
// markdown files.
// results is an array containing the errors (as a nested array) for each file.
Expand All @@ -34,6 +37,57 @@ function generateSummaryReport(results) {
return _chalk2.default.green('>>') + ' ' + results.length + ' ' + filePlural + ' ' + areOrIs + ' free from spelling errors';
}

var Stats = function Stats() {
var _this = this;

_classCallCheck(this, Stats);

this.values = {
'v0': 0,
'v1': 0,
'v10': 0,
'v50': 0,
'v100': 0,
'Total': 0
};
this.classify = function (val) {
//console.log(val);
if (val > 100) {
_this.values.v100++;
} else if (val > 50) {
_this.values.v50++;
} else if (val > 10) {
_this.values.v10++;
} else if (val > 1) {
_this.values.v1++;
} else {
_this.values.v0++;
}
_this.values.Total++;
};
this.readiness = function () {
var score = _this.values.v1 + _this.values.v10 * 5 + _this.values.v50 * 10 + _this.values.v100 * 15;
return 100 - (score > _this.values.Total ? 100 : score);
};
this.toString = function () {
return '\n ' + _this.values.v0 + ' files with 0 errors\n ' + _this.values.v1 + ' files with at least 1 error\n ' + _this.values.v10 + ' files with at least 10 errors\n ' + _this.values.v50 + ' files with at least 50 errors\n ' + _this.values.v100 + ' files with at least 100 errors\n\n Readiness indicator: ' + _this.readiness() + '%\n ';
};
};

// Generate a readiness report based on weighted values on errors per file


function generateReadinessReport(readiness, results) {
var stats = new Stats();
results.forEach(function (line) {
stats.classify(line.length);
});
if (stats.readiness() >= (isNaN(readiness) ? 100 : parseInt(readiness))) {
process.exitCode = 0;
}
return stats.toString();
}

// Generates a report for the errors found in a single markdown file.
function generateFileReport(file, spellingInfo) {
var report = ' ' + _chalk2.default.bold(file) + '\n';
Expand Down
6 changes: 5 additions & 1 deletion es6/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import chalk from 'chalk';
import multiFileProcessor from './multi-file-processor';
import relativeFileProcessor from './relative-file-processor';
import spellcheck from './spellcheck';
import { generateSummaryReport, generateFileReport } from './report-generator';
import { generateSummaryReport, generateFileReport, generateReadinessReport } from './report-generator';

const packageConfig = fs.readFileSync(path.join(__dirname, '../package.json'));
const buildVersion = JSON.parse(packageConfig).version;
Expand All @@ -26,6 +26,7 @@ program
.option('-a, --ignore-acronyms', 'Ignores acronyms.')
.option('-x, --no-suggestions', 'Do not suggest words (can be slow)')
.option('-t, --target-relative', 'Uses ".spelling" files relative to the target.')
.option('-y, --readiness [100]', 'Allows for a percentage readiness setting - default is set to 100 for no errors allowed')
.usage("[options] source-file source-file")
.parse(process.argv);

Expand Down Expand Up @@ -80,5 +81,8 @@ else {
}
}, (e, results) => {
console.log(generateSummaryReport(results));
if (program.readiness) {
console.log(generateReadinessReport(program.readiness, results));
}
});
}
65 changes: 64 additions & 1 deletion es6/report-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import context from './context';
// results is an array containing the errors (as a nested array) for each file.
export function generateSummaryReport(results) {
const errorCount = results.map((e) => e && e.length ? e.length : 0)
.reduce((p, c) => p + c, 0);
.reduce((p, c) => p + c, 0);

const filePlural = 'file' + (results.length > 1 ? 's' : '');
const errorPlural = 'error' + (errorCount > 1 ? 's' : '');
Expand All @@ -18,6 +18,69 @@ export function generateSummaryReport(results) {
return `${chalk.green('>>')} ${results.length} ${filePlural} ${areOrIs} free from spelling errors`;
}

class Stats {
constructor() {
this.values = {
'v0': 0,
'v1': 0,
'v10': 0,
'v50': 0,
'v100': 0,
'Total': 0
};
this.classify = (val) => {
//console.log(val);
if (val > 100) {
this.values.v100++;
}
else if (val > 50) {
this.values.v50++;
}
else if (val > 10) {
this.values.v10++;
}
else if (val > 1) {
this.values.v1++;
}
else {
this.values.v0++;
}
this.values.Total++;
};
this.readiness = () => {
let score = (this.values.v1) +
(this.values.v10 * 5) +
(this.values.v50 * 10) +
(this.values.v100 * 15);
return 100 - (score > this.values.Total ? 100 : score);
};
this.toString = () => {
return `
${this.values.v0} files with 0 errors
${this.values.v1} files with at least 1 error
${this.values.v10} files with at least 10 errors
${this.values.v50} files with at least 50 errors
${this.values.v100} files with at least 100 errors

Readiness indicator: ${this.readiness()}%
`;
};
}
}

// Generate a readiness report based on weighted values on errors per file
export function generateReadinessReport(readiness, results) {
let stats = new Stats();
results.forEach((line) => {
stats.classify(line.length);
});
if (stats.readiness() >= (isNaN(readiness) ? 100 : parseInt(readiness))) {
process.exitCode = 0;
}
return stats.toString();
}


// Generates a report for the errors found in a single markdown file.
export function generateFileReport(file, spellingInfo) {
let report = ` ${chalk.bold(file)}\n`;
Expand Down
17 changes: 17 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ Using the `--target-relative` (`-t`) option will augment the shared `.spelling`

Using the `--report` (`-r`) option will show a report of all the spelling mistakes that have been found. This mode is useful for CI build reports.

### Report readiness

Using the `--readiness` (`-y`) option will do two things:

* Create a readiness report by showing how many files contain spelling errors

```bash
59 files with 0 errors
5 files with at least 1 error
1 files with at least 10 errors
0 files with at least 50 errors
0 files with at least 100 errors

Readiness indicator: 90%
```
* Allow to pass a readiness threshold value which will determine if the tool throws an error or not. For example, passing a `-y 90` would allow the current state of the files to pass the CI build without throwing an error (defaults to 100, no errors).

## `.spelling` files

The `.spelling` file is self documenting as it includes...
Expand Down