Skip to content

Commit

Permalink
Changed the format of the reporter to use a default prefix of '[react…
Browse files Browse the repository at this point in the history
…-a11y]' to aid with identification and filtering in the console
  • Loading branch information
Erin Doyle committed Sep 1, 2018
1 parent 27d1ed3 commit d4b2256
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* eslint-disable babel/new-cap,no-console */
import {
browser,
AXURL
} from './util';

const LOG_PREFIX = '[react-a11y]:';

/**
* Throws an error based on the warning
* If the last argument is a DOM node, it
Expand Down Expand Up @@ -41,7 +44,7 @@ const showWarning = (...args) => {
const mkReporter = (opts) => {
const {
doThrow = false,
warningPrefix = ''
warningPrefix = LOG_PREFIX
} = opts;

return (info) => {
Expand All @@ -57,8 +60,8 @@ const mkReporter = (opts) => {

// build warning
const warning = [
displayName || tagName,
warningPrefix.concat(msg),
warningPrefix,
`${displayName || tagName} - ${msg}`,
...(url ? [`See '${url}' for more info.`] : []),
...(AX ? [`See '${AXURL(AX)}' for more info.`] : []),
DOMNode || tagName
Expand All @@ -82,7 +85,7 @@ const mkReporter = (opts) => {
*/
const deprecate = (opts, name, msg = '') => {
if (name in opts) {
console.warn(`react-a11y: the \`${name}\` options is deprecated. ${msg}`);
console.warn(`${LOG_PREFIX} the \`${name}\` options is deprecated. ${msg}`);
}
};

Expand All @@ -95,7 +98,7 @@ const deprecate = (opts, name, msg = '') => {
*/
const mandatory = (opts, name, msg = '') => {
if (!(name in opts)) {
throw new Error(`react-a11y: the \`${name}\` option is mandatory. ${msg}`);
throw new Error(`${LOG_PREFIX} the \`${name}\` option is mandatory. ${msg}`);
}
};

Expand Down Expand Up @@ -130,12 +133,12 @@ export default function (...args) {
] = props;

if (!React || !React.createElement) {
throw new Error('react-a11y: missing argument `React`');
throw new Error(`${LOG_PREFIX} missing argument 'React'`);
}

// make sure ReactDOM is passed in in browser code
if (browser && !(ReactDOM && ReactDOM.findDOMNode)) {
throw new Error('react-a11y: missing argument `ReactDOM`');
throw new Error(`${LOG_PREFIX} missing argument 'ReactDOM'`);
}

deprecate(opts, 'includeSrcNode', msg);
Expand Down

0 comments on commit d4b2256

Please sign in to comment.