Skip to content

Commit bd72878

Browse files
committed
showLintReportForCurrentDocument: add alert() config options
1 parent c04de81 commit bd72878

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ In a browser environment, the following public APIs are available:
9999
* `reporter` is a *reporter* function (see above for a definition). It will be called repeatedly with each lint problem as an argument.
100100
* `disabledIds` is an array of string linter IDs to disable
101101
* Returns nothing (i.e. `undefined`)
102-
* `bootlint.showLintReportForCurrentDocument(disabledIds)`: Lints the HTML of the current document and reports the linting results to the user.
103-
* If there are any lint warnings, one general notification message will be `window.alert()`-ed to the user. Each warning will be output individually using `console.warn()`.
102+
* `bootlint.showLintReportForCurrentDocument(disabledIds, alertOpts)`: Lints the HTML of the current document and reports the linting results to the user. Each warning will be output individually using `console.warn()`.
104103
* `disabledIds` is an array of string linter IDs to disable
104+
* `alertOpts` is an optional options object with the following properties:
105+
* `hasProblems` (type: `boolean`; default: `true`) - `window.alert()` a single general notification message to the user if there are any lint problems?
106+
* `problemFree` (type: `boolean`; default: `true`) - `window.alert()` a notification message to the user if the document has no lint problems?
105107
* Returns nothing (i.e. `undefined`)
106108

107109
### Node.js

src/bootlint.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -969,17 +969,26 @@ var LocationIndex = _location.LocationIndex;
969969
* If there are any lint warnings, one general notification message will be window.alert()-ed to the user.
970970
* Each warning will be output individually using console.warn().
971971
* @param {string[]} disabledIds Array of string IDs of linters to disable
972+
* @param {object} [alertOpts] Options object to configure alert()ing
973+
* @param {boolean} [alertOpts.hasProblems=true] Show one alert() when the first lint problem is found?
974+
* @param {boolean} [alertOpts.problemFree=true] Show one alert() at the end of linting if the page has no lint problems?
972975
* @returns {undefined} Nothing
973976
*/
974-
exports.showLintReportForCurrentDocument = function (disabledIds) {
977+
exports.showLintReportForCurrentDocument = function (disabledIds, alertOpts) {
978+
alertOpts = alertOpts || {};
979+
var alertOnFirstProblem = alertOpts.hasProblems || alertOpts.hasProblems === undefined;
980+
var alertIfNoProblems = alertOpts.problemFree || alertOpts.problemFree === undefined;
981+
975982
var seenLint = false;
976983
var errorCount = 0;
977984
var reporter = function (lint) {
978985
var background = "background: #" + (lint.id[0] === "W" ? "f0ad4e" : "d9534f") + "; color: #ffffff;";
979986
if (!seenLint) {
980-
/*eslint-disable no-alert, no-undef, block-scoped-var */
981-
window.alert("bootlint found errors in this document! See the JavaScript console for details.");// jshint ignore:line
982-
/*eslint-enable no-alert, no-undef, block-scoped-var */
987+
if (alertOnFirstProblem) {
988+
/*eslint-disable no-alert, no-undef, block-scoped-var */
989+
window.alert("bootlint found errors in this document! See the JavaScript console for details.");// jshint ignore:line
990+
/*eslint-enable no-alert, no-undef, block-scoped-var */
991+
}
983992
seenLint = true;
984993
}
985994

@@ -996,7 +1005,7 @@ var LocationIndex = _location.LocationIndex;
9961005
if (errorCount > 0) {
9971006
console.info("bootlint: For details, look up the lint problem IDs in the Bootlint wiki: https://github.com/twbs/bootlint/wiki");
9981007
}
999-
else {
1008+
else if (alertIfNoProblems) {
10001009
/*eslint-disable no-alert, no-undef, block-scoped-var */
10011010
window.alert("bootlint found no errors in this document.");// jshint ignore:line
10021011
/*eslint-enable no-alert, no-undef, block-scoped-var */

0 commit comments

Comments
 (0)