Skip to content

Commit 3cb951f

Browse files
author
Erin Doyle
authored
Merge pull request #12 from romeovs/eslint_update
Updated eslint and fixed findings
2 parents 36589bf + d0401be commit 3cb951f

37 files changed

Lines changed: 1503 additions & 1801 deletions

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib/
2+
webpack.config.js

.eslintrc

Lines changed: 52 additions & 365 deletions
Large diffs are not rendered by default.

.jshintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.jshintrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,19 @@
3737
"license": "MIT",
3838
"devDependencies": {
3939
"babel-cli": "^6.6.5",
40-
"babel-eslint": "^6.0.2",
4140
"babel-loader": "^6.2.4",
4241
"babel-plugin-transform-runtime": "^6.7.5",
4342
"babel-preset-es2015": "^6.6.0",
4443
"babel-preset-react": "^6.5.0",
4544
"babel-preset-stage-0": "^6.5.0",
4645
"babel-runtime": "^5.8.38",
4746
"chai": "^3.5.0",
48-
"eslint": "^2.7.0",
47+
"eslint": "^3.19.0",
48+
"eslint-config-airbnb": "^14.1.0",
4949
"eslint-plugin-babel": "^3.1.0",
50-
"eslint-plugin-react": "^4.2.3",
50+
"eslint-plugin-import": "^2.2.0",
51+
"eslint-plugin-jsx-a11y": "^3.0.2",
52+
"eslint-plugin-react": "^6.10.3",
5153
"karma": "^0.13.22",
5254
"karma-chrome-launcher": "^0.1.7",
5355
"karma-cli": "^0.1.2",

src/a11y.js

Lines changed: 116 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import after from './after'
2-
import validate from './options'
3-
import browser from './util/browser'
4-
import Suite from './test'
1+
import after from './after';
2+
import validate from './options';
3+
import browser from './util/browser';
4+
import Suite from './test';
55

66
export default class A11y {
77

@@ -11,140 +11,136 @@ export default class A11y {
1111
* @arg {object} options - the options
1212
* @returns {A11y} The react-a11y instance
1313
*/
14-
constructor (...args) {
15-
const {
14+
constructor(...args) {
15+
const {
1616
React
1717
, ReactDOM
1818
, ...options
19-
} = validate(...args)
19+
} = validate(...args);
2020

21-
this.options = options
22-
this.React = React
23-
this.ReactDOM = ReactDOM
24-
this.suite = new Suite(React, ReactDOM, this.options)
25-
this.patchReact()
26-
}
21+
this.options = options;
22+
this.React = React;
23+
this.ReactDOM = ReactDOM;
24+
this.suite = new Suite(React, ReactDOM, this.options);
25+
this.patchReact();
26+
}
2727

2828
/**
2929
* Patch React, replacing its createElement by our implementation
3030
* so we can run the tests
3131
* @returns {undefined}
3232
*/
33-
patchReact () {
34-
35-
// save old createElement
36-
this._createElement = this.React.createElement
37-
38-
const that = this
39-
this.React.createElement = function (klass, _props = {}, ...children) {
40-
41-
// fix for props = null
42-
const props = _props || {}
43-
44-
// create a refs object to hold the ref.
45-
// this needs to be an object so that it can be passed
46-
// by reference, and hold chaning state.
47-
const refs = typeof props.ref === 'string' ? props.ref : {}
48-
const ref = typeof props.ref === 'string'
49-
? props.ref
50-
: function (node) {
51-
refs.node = node
52-
53-
// maintain behaviour when ref prop was already set
54-
if ( typeof props.ref === 'function' ) {
55-
props.ref(node)
56-
}
57-
}
58-
59-
const newProps = typeof klass === 'string' ? { ...props, ref } : props
60-
61-
const reactEl = that._createElement(klass, newProps, ...children)
62-
63-
// only test html elements
64-
if (typeof klass === 'string') {
65-
66-
const handler = that.failureHandler(reactEl, refs)
67-
const childrenForTest = children.length === 0
68-
? props.children || []
69-
: children
70-
71-
that.suite.test(klass, props, childrenForTest, handler)
72-
}
73-
74-
return reactEl
33+
patchReact() {
34+
// save old createElement
35+
this._createElement = this.React.createElement;
36+
37+
const that = this;
38+
this.React.createElement = function (klass, _props = {}, ...children) {
39+
// fix for props = null
40+
const props = _props || {};
41+
42+
// create a refs object to hold the ref.
43+
// this needs to be an object so that it can be passed
44+
// by reference, and hold chaning state.
45+
const refs = typeof props.ref === 'string' ? props.ref : {};
46+
const ref = typeof props.ref === 'string'
47+
? props.ref
48+
: (node) => {
49+
refs.node = node;
50+
51+
// maintain behaviour when ref prop was already set
52+
if (typeof props.ref === 'function') {
53+
props.ref(node);
54+
}
55+
};
56+
57+
const newProps = typeof klass === 'string' ? { ...props, ref } : props;
58+
59+
const reactEl = that._createElement(klass, newProps, ...children);
60+
61+
// only test html elements
62+
if (typeof klass === 'string') {
63+
const handler = that.failureHandler(reactEl, refs);
64+
const childrenForTest = children.length === 0
65+
? props.children || []
66+
: children;
67+
68+
that.suite.test(klass, props, childrenForTest, handler);
69+
}
70+
71+
return reactEl;
72+
};
7573
}
76-
}
7774

78-
/**
79-
* Restore React and all components as if we were never here
80-
* @returns {undefined}
75+
/**
76+
* Restore React and all components as if we were never here
77+
* @returns {undefined}
8178
*/
82-
restoreAll () {
83-
this.React.createElement = this._createElement
84-
after.restorePatchedMethods()
85-
}
79+
restoreAll() {
80+
this.React.createElement = this._createElement;
81+
after.restorePatchedMethods();
82+
}
8683

8784
/**
8885
* Creates a failure handler based on the element that was created
8986
* @arg {object} reactEl - The react element this failure is for
9087
* @arg {object} ref - The object that holds the DOM node (passed by ref)
9188
* @returns {function} A handler that knows everything it needs to know
9289
*/
93-
failureHandler (reactEl, ref) {
94-
const {
95-
reporter
96-
, filterFn
97-
} = this.options
98-
99-
/**
100-
* @arg {string} errInfo - All the error info (see docs what this means)
101-
* @returns {undefined}
102-
*/
103-
return function (errInfo) {
104-
105-
// get the owning component (the one that has
106-
// the element in its render fn)
107-
const owner = reactEl._owner
108-
109-
// if there is an owner, use its name
110-
// if not, use the tagname of the violating elemnent
111-
const displayName = owner && owner.getName()
112-
113-
// stop if we're not allowed to proceed
114-
if ( !filterFn(displayName, errInfo.props.id, errInfo.msg) ) {
115-
return
116-
}
117-
118-
// gather all info for the reporter
119-
const info = {
120-
...errInfo
121-
, displayName
122-
}
123-
124-
// if we need to include the rendered node, we need to wait until
125-
// the owner has rendered
126-
// TODO: reduce the number of case where ther is no instance
127-
// by forcing every component to have one.
128-
if ( browser && !this.__sync && owner && owner._instance ) {
129-
const instance = owner._instance
130-
// Cannot log a node reference until the component is in the DOM,
131-
// so defer the call until componentDidMount or componentDidUpdate.
132-
after.render(instance, function () {
133-
// unpack the ref
134-
let DOMNode = false
135-
if ( typeof ref === 'string' ) {
136-
DOMNode = this.ReactDOM.findDOMNode(instance.refs[ref])
137-
} else if ( 'node' in ref ) {
138-
DOMNode = ref.node
139-
} else {
140-
throw new Error('could not resolve ref')
141-
}
142-
143-
reporter({ ...info, DOMNode })
144-
}.bind(this))
145-
} else {
146-
reporter(info)
147-
}
148-
}.bind(this)
149-
}
90+
failureHandler(reactEl, ref) {
91+
const {
92+
reporter,
93+
filterFn
94+
} = this.options;
95+
96+
/**
97+
* @arg {string} errInfo - All the error info (see docs what this means)
98+
* @returns {undefined}
99+
*/
100+
return function (errInfo) {
101+
// get the owning component (the one that has
102+
// the element in its render fn)
103+
const owner = reactEl._owner;
104+
105+
// if there is an owner, use its name
106+
// if not, use the tagname of the violating elemnent
107+
const displayName = owner && owner.getName();
108+
109+
// stop if we're not allowed to proceed
110+
if (!filterFn(displayName, errInfo.props.id, errInfo.msg)) {
111+
return;
112+
}
113+
114+
// gather all info for the reporter
115+
const info = {
116+
...errInfo,
117+
displayName
118+
};
119+
120+
// if we need to include the rendered node, we need to wait until
121+
// the owner has rendered
122+
// TODO: reduce the number of case where ther is no instance
123+
// by forcing every component to have one.
124+
if (browser && !this.__sync && owner && owner._instance) {
125+
const instance = owner._instance;
126+
// Cannot log a node reference until the component is in the DOM,
127+
// so defer the call until componentDidMount or componentDidUpdate.
128+
after.render(instance, () => {
129+
// unpack the ref
130+
let DOMNode = false;
131+
if (typeof ref === 'string') {
132+
DOMNode = this.ReactDOM.findDOMNode(instance.refs[ref]); // TODO: replace use of findDOMNode
133+
} else if ('node' in ref) {
134+
DOMNode = ref.node;
135+
} else {
136+
throw new Error('could not resolve ref');
137+
}
138+
139+
reporter({ ...info, DOMNode });
140+
});
141+
} else {
142+
reporter(info);
143+
}
144+
}.bind(this);
145+
}
150146
}

src/after.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11

22
// store how to undo these changes
3-
let restoreFunctions = []
3+
let restoreFunctions = [];
44

55
// does nothing
6-
const noop = () => null
6+
const noop = () => null;
77

8-
const after = function (host, name, cb) {
9-
if ( !host ) {
10-
throw new Error('cannot replace function on undefined')
11-
}
8+
const after = (host, name, cb) => {
9+
if (!host) {
10+
throw new Error('cannot replace function on undefined');
11+
}
1212

13-
// save original
14-
const original = host[name] || noop
13+
// save original
14+
const original = host[name] || noop;
1515

16-
// override host
17-
host[name] = function (...args) {
16+
// override host
17+
host[name] = (...args) => {
1818
// perform original
19-
original.apply(this, args)
19+
original.apply(this, args);
2020
// perform cb
21-
cb.apply(this, args)
22-
}
21+
cb.apply(this, args);
22+
};
2323

24-
// save restoring function
25-
restoreFunctions.push(function () {
26-
host[name] = original
27-
})
28-
}
24+
// save restoring function
25+
restoreFunctions.push(() => {
26+
host[name] = original;
27+
});
28+
};
2929

30-
after.restorePatchedMethods = function () {
31-
// perform each restoring function
32-
restoreFunctions.forEach(restore => restore())
30+
after.restorePatchedMethods = () => {
31+
// perform each restoring function
32+
restoreFunctions.forEach(restore => restore());
3333

34-
// clear the list of functions to restore
35-
restoreFunctions = []
36-
}
34+
// clear the list of functions to restore
35+
restoreFunctions = [];
36+
};
3737

38-
after.render = function (component, fn) {
39-
after(component, 'componentDidMount', fn)
40-
after(component, 'componentDidUpdate', fn)
41-
}
38+
after.render = (component, fn) => {
39+
after(component, 'componentDidMount', fn);
40+
after(component, 'componentDidUpdate', fn);
41+
};
4242

43-
export default after
43+
export default after;

0 commit comments

Comments
 (0)