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": {
"quotes": [2, "single"],
"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,
choiceId,
activateOptions,
}
};
};
export const removeItem = (id, choiceId) => {
@ -14,7 +14,7 @@ export const removeItem = (id, choiceId) => {
type: 'REMOVE_ITEM',
id,
choiceId,
}
};
};
export const highlightItem = (id, highlighted) => {
@ -22,7 +22,7 @@ export const highlightItem = (id, highlighted) => {
type: 'HIGHLIGHT_ITEM',
id,
highlighted,
}
};
};
export const addChoice = (value, label, id, groupId, disabled) => {
@ -33,21 +33,21 @@ export const addChoice = (value, label, id, groupId, disabled) => {
id,
groupId,
disabled,
}
};
};
export const filterChoices = (results) => {
return {
type: 'FILTER_CHOICES',
results,
}
};
};
export const activateChoices = (active = true) => {
return {
type: 'ACTIVATE_CHOICES',
active,
}
};
};
export const addGroup = (value, id, active, disabled) => {
@ -57,11 +57,11 @@ export const addGroup = (value, id, active, disabled) => {
id,
active,
disabled,
}
};
};
export const clearAll = () => {
return {
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
// Reference: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from
if (!Array.from) {

View file

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

View file

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

View file

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

View file

@ -6,14 +6,14 @@ import choices from './choices';
const appReducer = combineReducers({
items,
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
// 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
if (action.type === 'CLEAR_ALL') {
state = undefined;

View file

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

View file

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

View file

@ -27,12 +27,18 @@
"devDependencies": {
"autoprefixer": "^6.3.3",
"babel-core": "^6.7.2",
"babel-eslint": "^6.1.2",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0",
"csso": "^1.7.0",
"csso": "^1.8.2",
"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",
"karma": "^1.1.0",
"karma-coverage": "^1.0.0",
@ -52,6 +58,7 @@
"wrapper-webpack-plugin": "^0.1.7"
},
"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',
publicPath: '/assets/scripts/dist/'
},
eslint: {
configFile: '.eslintrc'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
@ -24,7 +27,7 @@ module.exports = {
loaders: [{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loaders: ['babel'],
loaders: ['babel', 'eslint-loader'],
include: path.join(__dirname, 'assets/scripts/src')
}]
}