ESLint entire project

This commit is contained in:
Josh Johnson 2016-08-14 22:14:37 +01:00
parent 330eb73594
commit 9f0dc2c8dc
14 changed files with 629 additions and 608 deletions

View file

@ -10,5 +10,15 @@
"rules": { "rules": {
"quotes": [2, "single"], "quotes": [2, "single"],
"strict": [2, "never"], "strict": [2, "never"],
"indent": ["error", 4, {"SwitchCase": 1}],
"eol-last": "off",
"arrow-body-style": "off",
"no-underscore-dangle": "off",
"no-new": 0,
"max-len": "off",
"no-console": ["error", { allow: ["warn", "error"] }],
"consistent-return": "off",
"no-param-reassign": ["error", { "props": false }],
"no-unused-vars": ["error", { "args": "none" }]
}, },
} }

8
.eslintrc.js Normal file
View file

@ -0,0 +1,8 @@
module.exports = {
"extends": "airbnb",
"plugins": [
"react",
"jsx-a11y",
"import"
]
};

File diff suppressed because one or more lines are too long

View file

@ -6,7 +6,7 @@ export const addItem = (value, label, id, choiceId, activateOptions) => {
id, id,
choiceId, choiceId,
activateOptions, activateOptions,
} };
}; };
export const removeItem = (id, choiceId) => { export const removeItem = (id, choiceId) => {
@ -14,7 +14,7 @@ export const removeItem = (id, choiceId) => {
type: 'REMOVE_ITEM', type: 'REMOVE_ITEM',
id, id,
choiceId, choiceId,
} };
}; };
export const highlightItem = (id, highlighted) => { export const highlightItem = (id, highlighted) => {
@ -22,7 +22,7 @@ export const highlightItem = (id, highlighted) => {
type: 'HIGHLIGHT_ITEM', type: 'HIGHLIGHT_ITEM',
id, id,
highlighted, highlighted,
} };
}; };
export const addChoice = (value, label, id, groupId, disabled) => { export const addChoice = (value, label, id, groupId, disabled) => {
@ -33,21 +33,21 @@ export const addChoice = (value, label, id, groupId, disabled) => {
id, id,
groupId, groupId,
disabled, disabled,
} };
}; };
export const filterChoices = (results) => { export const filterChoices = (results) => {
return { return {
type: 'FILTER_CHOICES', type: 'FILTER_CHOICES',
results, results,
} };
}; };
export const activateChoices = (active = true) => { export const activateChoices = (active = true) => {
return { return {
type: 'ACTIVATE_CHOICES', type: 'ACTIVATE_CHOICES',
active, active,
} };
}; };
export const addGroup = (value, id, active, disabled) => { export const addGroup = (value, id, active, disabled) => {
@ -57,11 +57,11 @@ export const addGroup = (value, id, active, disabled) => {
id, id,
active, active,
disabled, disabled,
} };
}; };
export const clearAll = () => { export const clearAll = () => {
return { return {
type: 'CLEAR_ALL', type: 'CLEAR_ALL',
} };
}; };

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,5 @@
/* eslint-disable */
// Production steps of ECMA-262, Edition 6, 22.1.2.1 // Production steps of ECMA-262, Edition 6, 22.1.2.1
// Reference: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from // Reference: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from
if (!Array.from) { if (!Array.from) {

View file

@ -1,6 +1,4 @@
export const hasClass = (elem, className) => { /* eslint-disable */
return new RegExp(' ' + className + ' ').test(' ' + elem.className + ' ');
}
/** /**
* Capitalises the first letter of each word in a string * Capitalises the first letter of each word in a string
@ -46,7 +44,7 @@ export const isElement = (o) => {
typeof HTMLElement === "object" ? o instanceof HTMLElement : //DOM2 typeof HTMLElement === "object" ? o instanceof HTMLElement : //DOM2
o && typeof o === "object" && o !== null && o.nodeType === 1 && typeof o.nodeName==="string" o && typeof o === "object" && o !== null && o.nodeType === 1 && typeof o.nodeName==="string"
); );
} };
/** /**
* Merges unspecified amount of objects into new object * Merges unspecified amount of objects into new object
@ -111,7 +109,7 @@ export const whichTransitionEvent = function(){
return transitions[t]; return transitions[t];
} }
} }
} };
/** /**
* CSS animation end event listener * CSS animation end event listener
@ -374,7 +372,7 @@ export const isScrolledIntoView = (el, parent, direction = 1) => {
} }
return isVisible; return isVisible;
} };
/** /**
* Remove html tags from a string * Remove html tags from a string
@ -414,7 +412,7 @@ export const addAnimation = (el, animation) => {
*/ */
export const getRandomNumber = function(min, max) { export const getRandomNumber = function(min, max) {
return Math.floor(Math.random() * (max - min) + min); return Math.floor(Math.random() * (max - min) + min);
} };
/** /**
* Turn a string into a node * Turn a string into a node

View file

@ -1,22 +1,28 @@
const choices = (state = [], action) => { const choices = (state = [], action) => {
switch (action.type) { switch (action.type) {
case 'ADD_CHOICE': case 'ADD_CHOICE': {
/*
A disabled choice appears in the choice dropdown but cannot be selected
A selected choice has been added to the passed input's value (added as an item)
An active choice appears within the choice dropdown
*/
return [...state, { return [...state, {
id: action.id, id: action.id,
groupId: action.groupId, groupId: action.groupId,
value: action.value, value: action.value,
label: action.label, label: action.label,
disabled: action.disabled, // A disabled choice appears in the choice dropdown but cannot be selected disabled: action.disabled,
selected: false, // A selected choice has been added to the passed input's value (added as an item) selected: false,
active: true, // An active choice appears within the choice dropdown active: true,
score: 9999, score: 9999,
}]; }];
}
case 'ADD_ITEM': case 'ADD_ITEM': {
let newState = state; let newState = state;
// If all choices need to be activated // If all choices need to be activated
if(action.activateOptions) { if (action.activateOptions) {
newState = state.map((choice) => { newState = state.map((choice) => {
choice.active = action.active; choice.active = action.active;
return choice; return choice;
@ -24,9 +30,9 @@ const choices = (state = [], action) => {
} }
// When an item is added and it has an associated choice, // When an item is added and it has an associated choice,
// we want to disable it so it can't be chosen again // we want to disable it so it can't be chosen again
if(action.choiceId > -1) { if (action.choiceId > -1) {
newState = state.map((choice) => { newState = state.map((choice) => {
if(choice.id === parseInt(action.choiceId)) { if (choice.id === parseInt(action.choiceId, 10)) {
choice.selected = true; choice.selected = true;
} }
return choice; return choice;
@ -34,48 +40,54 @@ const choices = (state = [], action) => {
} }
return newState; return newState;
}
case 'REMOVE_ITEM': case 'REMOVE_ITEM': {
// When an item is removed and it has an associated choice, // When an item is removed and it has an associated choice,
// we want to re-enable it so it can be chosen again // we want to re-enable it so it can be chosen again
if(action.choiceId > -1) { if (action.choiceId > -1) {
return state.map((choice) => { return state.map((choice) => {
if(choice.id === parseInt(action.choiceId)) { if (choice.id === parseInt(action.choiceId, 10)) {
choice.selected = false; choice.selected = false;
} }
return choice; return choice;
}); });
} else {
return state;
} }
case 'FILTER_CHOICES': return state;
}
case 'FILTER_CHOICES': {
const filteredResults = action.results; const filteredResults = action.results;
const filteredState = state.map((choice, index) => { const filteredState = state.map((choice) => {
// Set active state based on whether choice is // Set active state based on whether choice is
// within filtered results // within filtered results
choice.active = filteredResults.some((result) => { choice.active = filteredResults.some((result) => {
if(result.item.id === choice.id) { if (result.item.id === choice.id) {
choice.score = result.score; choice.score = result.score;
return true; return true;
} }
return false;
}); });
return choice; return choice;
}); });
return filteredState; return filteredState;
}
case 'ACTIVATE_CHOICES': case 'ACTIVATE_CHOICES': {
return state.map((choice) => { return state.map((choice) => {
choice.active = action.active; choice.active = action.active;
return choice; return choice;
}); });
}
default: default: {
return state; return state;
}
} }
} };
export default choices; export default choices;

View file

@ -1,16 +1,18 @@
const groups = (state = [], action) => { const groups = (state = [], action) => {
switch (action.type) { switch (action.type) {
case 'ADD_GROUP': case 'ADD_GROUP': {
return [...state, { return [...state, {
id: action.id, id: action.id,
value: action.value, value: action.value,
active: action.active, active: action.active,
disabled: action.disabled, disabled: action.disabled,
}]; }];
}
default: default: {
return state; return state;
}
} }
} };
export default groups; export default groups;

View file

@ -6,14 +6,14 @@ import choices from './choices';
const appReducer = combineReducers({ const appReducer = combineReducers({
items, items,
groups, groups,
choices choices,
}); });
const rootReducer = (state, action) => { const rootReducer = (passedState, action) => {
let state = passedState;
// If we are clearing all items, groups and options we reassign // If we are clearing all items, groups and options we reassign
// state and then pass that state to our proper reducer. This isn't // state and then pass that state to our proper reducer. This isn't
// mutating our actual state. // mutating our actual state
//
// See: http://stackoverflow.com/a/35641992 // See: http://stackoverflow.com/a/35641992
if (action.type === 'CLEAR_ALL') { if (action.type === 'CLEAR_ALL') {
state = undefined; state = undefined;

View file

@ -1,43 +1,47 @@
const items = (state = [], action) => { const items = (state = [], action) => {
switch (action.type) { switch (action.type) {
case 'ADD_ITEM': case 'ADD_ITEM': {
// Add object to items array // Add object to items array
let newState = [...state, { const newState = [...state, {
id: action.id, id: action.id,
choiceId: action.choiceId, choiceId: action.choiceId,
value: action.value, value: action.value,
label: action.label, label: action.label,
active: true, active: true,
highlighted: false highlighted: false,
}]; }];
return newState.map((item) => { return newState.map((item) => {
if(item.highlighted) { if (item.highlighted) {
item.highlighted = false; item.highlighted = false;
} }
return item; return item;
}); });
}
case 'REMOVE_ITEM': case 'REMOVE_ITEM': {
// Set item to inactive // Set item to inactive
return state.map((item) => { return state.map((item) => {
if(item.id === action.id) { if (item.id === action.id) {
item.active = false; item.active = false;
} }
return item; return item;
}); });
}
case 'HIGHLIGHT_ITEM': case 'HIGHLIGHT_ITEM': {
return state.map((item) => { return state.map((item) => {
if(item.id === action.id) { if (item.id === action.id) {
item.highlighted = action.highlighted; item.highlighted = action.highlighted;
} }
return item; return item;
}); });
}
default: default: {
return state; return state;
}
} }
} };
export default items; export default items;

View file

@ -1,10 +1,7 @@
'use strict';
import { createStore } from 'redux'; import { createStore } from 'redux';
import rootReducer from './../reducers/index.js'; import rootReducer from './../reducers/index.js';
export default class Store {
export class Store {
constructor() { constructor() {
this.store = createStore( this.store = createStore(
rootReducer, rootReducer,
@ -53,7 +50,6 @@ export class Store {
*/ */
getItemsFilteredByActive() { getItemsFilteredByActive() {
const items = this.getItems(); const items = this.getItems();
const values = items.filter((item) => { const values = items.filter((item) => {
return item.active === true; return item.active === true;
}, []); }, []);
@ -80,7 +76,6 @@ export class Store {
*/ */
getChoices() { getChoices() {
const state = this.store.getState(); const state = this.store.getState();
return state.choices; return state.choices;
} }
@ -90,10 +85,9 @@ export class Store {
*/ */
getChoicesFilteredByActive() { getChoicesFilteredByActive() {
const choices = this.getChoices(); const choices = this.getChoices();
const values = choices.filter((choice) => { const values = choices.filter((choice) => {
return choice.active === true; return choice.active === true;
},[]); }, []);
return values; return values;
} }
@ -106,7 +100,7 @@ export class Store {
const choices = this.getChoices(); const choices = this.getChoices();
const values = choices.filter((choice) => { const values = choices.filter((choice) => {
return choice.disabled !== true; return choice.disabled !== true;
},[]); }, []);
return values; return values;
} }
@ -116,11 +110,12 @@ export class Store {
* @return {Object} Found choice * @return {Object} Found choice
*/ */
getChoiceById(id) { getChoiceById(id) {
if(!id) return; if (id) {
const choices = this.getChoicesFilteredByActive(); const choices = this.getChoicesFilteredByActive();
const foundChoice = choices.find((choice) => choice.id === parseInt(id)); const foundChoice = choices.find((choice) => choice.id === parseInt(id, 10));
return foundChoice;
return foundChoice; }
return false;
} }
/** /**
@ -145,11 +140,11 @@ export class Store {
const hasActiveOptions = choices.some((choice) => { const hasActiveOptions = choices.some((choice) => {
return choice.active === true && choice.disabled === false; return choice.active === true && choice.disabled === false;
}); });
return isActive && hasActiveOptions ? true : false; return isActive && hasActiveOptions;
},[]); }, []);
return values; return values;
} }
}; }
module.exports = Store; module.exports = Store;

View file

@ -27,12 +27,18 @@
"devDependencies": { "devDependencies": {
"autoprefixer": "^6.3.3", "autoprefixer": "^6.3.3",
"babel-core": "^6.7.2", "babel-core": "^6.7.2",
"babel-eslint": "^6.1.2",
"babel-loader": "^6.2.4", "babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.6.0", "babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0", "babel-preset-stage-0": "^6.5.0",
"csso": "^1.7.0", "csso": "^1.8.2",
"es6-promise": "^3.2.1", "es6-promise": "^3.2.1",
"fuse.js": "^2.2.0", "eslint": "^3.3.0",
"eslint-config-airbnb": "^10.0.1",
"eslint-loader": "^1.5.0",
"eslint-plugin-import": "^1.13.0",
"eslint-plugin-jsx-a11y": "^2.1.0",
"eslint-plugin-react": "^6.1.0",
"jasmine-core": "^2.4.1", "jasmine-core": "^2.4.1",
"karma": "^1.1.0", "karma": "^1.1.0",
"karma-coverage": "^1.0.0", "karma-coverage": "^1.0.0",
@ -52,6 +58,7 @@
"wrapper-webpack-plugin": "^0.1.7" "wrapper-webpack-plugin": "^0.1.7"
}, },
"dependencies": { "dependencies": {
"redux": "^3.3.1" "redux": "^3.3.1",
"fuse.js": "^2.2.0"
} }
} }

View file

@ -12,6 +12,9 @@ module.exports = {
filename: 'choices.min.js', filename: 'choices.min.js',
publicPath: '/assets/scripts/dist/' publicPath: '/assets/scripts/dist/'
}, },
eslint: {
configFile: '.eslintrc'
},
plugins: [ plugins: [
new webpack.HotModuleReplacementPlugin(), new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
@ -24,7 +27,7 @@ module.exports = {
loaders: [{ loaders: [{
test: /\.js$/, test: /\.js$/,
exclude: /(node_modules|bower_components)/, exclude: /(node_modules|bower_components)/,
loaders: ['babel'], loaders: ['babel', 'eslint-loader'],
include: path.join(__dirname, 'assets/scripts/src') include: path.join(__dirname, 'assets/scripts/src')
}] }]
} }