Skip to content

Commit 66622bd

Browse files
committed
Update eslint and apply leankit rules
1 parent 202e5fa commit 66622bd

24 files changed

+173
-158
lines changed

.eslintrc

-18
This file was deleted.

.eslintrc.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
extends: [ "leankit" ],
3+
globals: {
4+
lux:true,
5+
postal:true
6+
},
7+
rules:{
8+
"valid-jsdoc": "off"
9+
}
10+
};

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ bower/
1717
public/js/lib/
1818
js-dist/
1919
coverage/
20+
.vscode/

karma.conf.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ module.exports = function( config ) {
2525

2626
// list of files / patterns to load in the browser
2727
files: [
28-
"spec/helpers/phantomjs-shims.js",
29-
"spec/helpers/karma-setup.js",
30-
"spec/**/*.spec.*"
28+
"spec/helpers/phantomjs-shims.js",
29+
"spec/helpers/karma-setup.js",
30+
"spec/**/*.spec.*"
3131
],
3232

3333
// list of files to exclude
@@ -62,7 +62,7 @@ module.exports = function( config ) {
6262

6363
// start these browsers
6464
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
65-
browsers: [ "Chrome" /*, "Safari", "Firefox" */ ],
65+
browsers: [ "Chrome" /* , "Safari", "Firefox" */ ],
6666

6767
coverageReporter: {
6868
reporters: [

package.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@
4141
"LeanKit"
4242
],
4343
"scripts": {
44+
"prebuild":"npm run lint",
4445
"build": "webpack --config webpack.config.js",
46+
"pretest": "npm run lint",
4547
"test": "karma start --no-auto-watch --single-run",
46-
"coverage": "npm run test"
48+
"coverage": "npm run test",
49+
"lint": "$(npm bin)/eslint --ext=js,jsx ./spec/ ./src/ --fix"
4750
},
4851
"peerDependencies": {
4952
"babel": "6.x",
@@ -57,6 +60,7 @@
5760
"devDependencies": {
5861
"babel": "6.x",
5962
"babel-core": "^6.14.0",
63+
"babel-eslint": "^7.0.0",
6064
"babel-loader": "^6.2.5",
6165
"babel-plugin-add-module-exports": "^0.2.1",
6266
"babel-polyfill": "^6.13.0",
@@ -66,6 +70,10 @@
6670
"chai": "^3.5.0",
6771
"clean-webpack-plugin": "^0.1.10",
6872
"dirty-chai": "^1.2.2",
73+
"eslint": "^3.5.0",
74+
"eslint-config-leankit": "^2.0.0",
75+
"eslint-plugin-babel": "^3.3.0",
76+
"eslint-plugin-react": "~3.11.3",
6977
"gulp": "^3.8.8",
7078
"gulp-changed": "^1.2.1",
7179
"gulp-eslint": "^0.15.0",

spec/.eslintrc

-36
This file was deleted.

spec/.eslintrc.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
extends: ["leankit/test","leankit/react"],
3+
globals:{
4+
React:true,
5+
ReactDOM:true,
6+
utils:true,
7+
_:true
8+
}
9+
};

spec/actions.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe( "luxJS - Actions", function() {
4242
var handlerOne = sinon.spy();
4343
var handlerTwo = sinon.spy();
4444
var customAction = {
45-
[ actionName]: handlerOne
45+
[ actionName ]: handlerOne
4646
};
4747

4848
lux.customActionCreator( customAction );

spec/helpers/phantomjs-shims.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// From https://github.com/newtriks/react-automation-example/blob/master/test/helpers/phantomjs-shims.js
22

3+
/* eslint-disable consistent-this */
4+
35
( function() {
46
var Ap = Array.prototype;
57
var slice = Ap.slice;
@@ -32,4 +34,6 @@
3234
return bound;
3335
};
3436
}
35-
} )();
37+
}() );
38+
39+
/* eslint-enable consistent-this */

spec/luxWrapper.spec.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
var luxWrapper = lux.luxWrapper;
23
function storeFactory( options ) {
34
options = Object.assign( {
@@ -15,7 +16,7 @@ function getMockReactComponent( options ) {
1516
return { foo: "bar" };
1617
},
1718
render: function() {
18-
return React.createElement( "div", { className: "childy" }, "This is a test DIV" );
19+
return React.createElement( "div", { displayName: "MOM", className: "childy" }, "This is a test DIV" );
1920
}
2021
}, options ) );
2122
}
@@ -123,11 +124,11 @@ describe( "luxWrapper", function() {
123124
} );
124125
it( "should pass expected props to the targetComponent", function() {
125126
willReceivePropsStub.should.be.calledWith( {
126-
foo: "bar",
127-
wrapperProp: "thingy",
128-
store2: "statey state state",
129-
store1: "state"
130-
} );
127+
foo: "bar",
128+
wrapperProp: "thingy",
129+
store2: "statey state state",
130+
store1: "state"
131+
} );
131132
} );
132133
} );
133134
} );
@@ -142,6 +143,10 @@ describe( "luxWrapper", function() {
142143
}
143144
} );
144145
targetComponent = React.createClass( {
146+
propTypes: {
147+
onThingThang: React.PropTypes.string,
148+
onAnotherThang: React.PropTypes.string
149+
},
145150
displayName: "ActionMockt",
146151
handleClick: function( e ) {
147152
this.props.onThingThang( e, "another", "value" );

spec/store.spec.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
describe( "luxJS - Store", function() {
2+
// eslint-disable-next-line max-params
23
function storeFactory( options, m1, m2, m3, m4, m5, m6, m7 ) {
34
options = Object.assign( {
45
namespace: "storeOne",
@@ -35,6 +36,7 @@ describe( "luxJS - Store", function() {
3536
} );
3637
} ).should.throw( /must have a namespace/ );
3738
} );
39+
3840
it( "Should throw an error if there are no action handlers", function() {
3941
var tmpStore;
4042
( function() {
@@ -248,15 +250,15 @@ describe( "luxJS - Store", function() {
248250
}
249251
}
250252
}, {
251-
handlers: {
252-
backInTime: {
253-
waitFor: [ "mefirst" ],
254-
handler: function() {
255-
invocations.push( "mesecond-mixin2" );
256-
}
253+
handlers: {
254+
backInTime: {
255+
waitFor: [ "mefirst" ],
256+
handler: function() {
257+
invocations.push( "mesecond-mixin2" );
257258
}
258259
}
259-
} );
260+
}
261+
} );
260262

261263
var store3 = storeFactory(
262264
{
@@ -437,8 +439,10 @@ describe( "luxJS - Store", function() {
437439
lux.dispatch( "myTest" );
438440
storeOne.should.be.calledOnce();
439441

442+
/* eslint-disable no-console */
440443
console.warn.should.be.calledOnce.and.calledWithMatch( /doesNotExist/ );
441444
console.warn.restore();
445+
/* eslint-enable no-console */
442446

443447
store.dispose();
444448
} );

src/.eslintrc.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
extends: [ "leankit/es6", "leankit/react" ],
3+
parser: "babel-eslint",
4+
plugins: [ "babel" ],
5+
rules: {
6+
"no-unused-expressions": 2,
7+
"prefer-arrow-callback": 0,
8+
"init-declarations": 0,
9+
"react/jsx-key": [ 2 ],
10+
11+
// plugin for babel eslint to fix some problems with the core rules
12+
"generator-star-spacing": 0,
13+
"babel/generator-star-spacing": [ "error" ],
14+
"object-curly-spacing": 0,
15+
"babel/object-curly-spacing": [ "error", "always" ],
16+
"object-shorthand": 0,
17+
"babel/object-shorthand": [ "error", "always" ],
18+
"arrow-parens": 0,
19+
"babel/arrow-parens": [ "error", "as-needed" ],
20+
"babel/no-await-in-loop": "error" // nothing to disable
21+
}
22+
};

src/actions.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function generateActionCreator( actionList ) {
88
actionList.forEach( function( action ) {
99
if ( !actions[ action ] ) {
1010
actions[ action ] = function() {
11-
var args = Array.from( arguments );
11+
const args = Array.from( arguments );
1212
actionChannel.publish( {
1313
topic: `execute.${action}`,
1414
data: {
@@ -27,17 +27,16 @@ export function generateActionCreator( actionList ) {
2727
export function getActionGroup( group ) {
2828
if ( actionGroups[ group ] ) {
2929
return _.pick( actions, actionGroups[ group ] );
30-
} else {
31-
throw new Error( `There is no action group named '${group}'` );
3230
}
31+
throw new Error( `There is no action group named '${group}'` );
3332
}
3433

3534
// This method is deprecated, but will remain as
3635
// long as the print utils need it.
3736
/* istanbul ignore next */
3837
export function getGroupsWithAction( actionName ) {
3938
const groups = [];
40-
for ( var [ group, list ] of entries( actionGroups ) ) {
39+
for ( const [ group, list ] of entries( actionGroups ) ) {
4140
if ( list.indexOf( actionName ) >= 0 ) {
4241
groups.push( group );
4342
}

0 commit comments

Comments
 (0)