Skip to content

Commit d4b2256

Browse files
author
Erin Doyle
committed
Changed the format of the reporter to use a default prefix of '[react-a11y]' to aid with identification and filtering in the console
1 parent 27d1ed3 commit d4b2256

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/options.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
/* eslint-disable babel/new-cap,no-console */
12
import {
23
browser,
34
AXURL
45
} from './util';
56

7+
const LOG_PREFIX = '[react-a11y]:';
8+
69
/**
710
* Throws an error based on the warning
811
* If the last argument is a DOM node, it
@@ -41,7 +44,7 @@ const showWarning = (...args) => {
4144
const mkReporter = (opts) => {
4245
const {
4346
doThrow = false,
44-
warningPrefix = ''
47+
warningPrefix = LOG_PREFIX
4548
} = opts;
4649

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

5861
// build warning
5962
const warning = [
60-
displayName || tagName,
61-
warningPrefix.concat(msg),
63+
warningPrefix,
64+
`${displayName || tagName} - ${msg}`,
6265
...(url ? [`See '${url}' for more info.`] : []),
6366
...(AX ? [`See '${AXURL(AX)}' for more info.`] : []),
6467
DOMNode || tagName
@@ -82,7 +85,7 @@ const mkReporter = (opts) => {
8285
*/
8386
const deprecate = (opts, name, msg = '') => {
8487
if (name in opts) {
85-
console.warn(`react-a11y: the \`${name}\` options is deprecated. ${msg}`);
88+
console.warn(`${LOG_PREFIX} the \`${name}\` options is deprecated. ${msg}`);
8689
}
8790
};
8891

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

@@ -130,12 +133,12 @@ export default function (...args) {
130133
] = props;
131134

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

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

141144
deprecate(opts, 'includeSrcNode', msg);

0 commit comments

Comments
 (0)