Skip to content

Commit

Permalink
More lint
Browse files Browse the repository at this point in the history
  • Loading branch information
osteele committed May 17, 2018
1 parent 5d5e9c7 commit 4bd6f63
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 44 deletions.
31 changes: 9 additions & 22 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,27 @@ globals:
process: false # allow webpack `process.env[*]` variables

rules:
max-len: [warn, { code: 100 }]
# exceptions from eslint:recommended:
# Intentional exceptions to Airbnb rules:
no-alert: off # currently used in the UI
no-plusplus: [error, allowForLoopAfterthoughts: true]
no-underscore-dangle: [error, allow: [__REDUX_DEVTOOLS_EXTENSION_COMPOSE__]]
no-unused-vars: [error, argsIgnorePattern: "^_" ]
# exceptions from plugin:react/recommended:
react/no-find-dom-node: warn
react/prop-types: off # TODO: #123
react/jsx-no-target-blank: off

# Airbnb style exceptions that we'll eventually fix:
import/prefer-default-export: warn
# Airbnb exceptions that we should fix:
no-console: off
no-param-reassign: warn
no-restricted-globals: warn
prefer-destructuring: warn
react/forbid-prop-types: warn
react/jsx-no-target-blank: warn
react/no-unused-state: warn
react/prefer-stateless-function: warn
react/no-find-dom-node: warn
react/prop-types: off # TODO: #123
react/require-default-props: warn
react/sort-comp: warn
no-console: off

# Intentional Airbnb exceptions:
no-alert: off # currently used in the UI
no-plusplus: [error, allowForLoopAfterthoughts: true]
no-underscore-dangle: [error, allow: [__REDUX_DEVTOOLS_EXTENSION_COMPOSE__]]

# TODO: #118 accessibility
jsx-a11y/anchor-is-valid: off
jsx-a11y/click-events-have-key-events: off
jsx-a11y/label-has-for: off
jsx-a11y/no-static-element-interactions: off

# Fixable exceptions to Airbnb style guide.
react/jsx-indent: off

overrides:
# server:
- files: [ "index.html.js", "server.js", "webpack.config.js" ]
Expand Down
File renamed without changes.
8 changes: 6 additions & 2 deletions src/data/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@ export function eventDeleteFailed(event, error) {

/**
* Triggers showing the event details page.
*
* This function adds a `recId` property to the event.
*
* @param {object} event - the event data of the event to view
*/
export function viewEvent(event) {
Expand Down Expand Up @@ -518,15 +521,16 @@ export function fetchLabels() {
* @param {object} labels - a dictionary of label names and information
*/
export function setLabels(labels) {
let data = labels;
if (Object.prototype.toString.call(labels) === '[object Array]') {
// Convert array to object
const labelsMap = {};
labels.forEach((label) => {
labelsMap[label.name] = label;
});
labels = labelsMap;
data = labelsMap;
}
return { type: ActionTypes.SET_LABELS, data: labels };
return { type: ActionTypes.SET_LABELS, data };
}

/**
Expand Down
40 changes: 20 additions & 20 deletions src/pages/add-edit/location-field.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
import * as React from 'react';

export default class LocationField extends React.Component {
static stringMatches(str, substrings) {
const s = str.trim();
for (let i = 0; i < substrings.length; ++i) {
if (s === substrings[i]) {
return true;
}
}
return false;
}

constructor(props) {
super(props);
this.state = {
building: null,
room: null,
suffix: null,
isOlin: false,
value: this.props.location,
};

// Matching substrings for each building. Should be lowercase.
Expand Down Expand Up @@ -82,7 +91,7 @@ export default class LocationField extends React.Component {
}

textChanged = (e) => {
const value = e.target.value;
const { value } = e.target;
const parsed = this.tryParseLocationInput(value);
const locationObj = {
building: parsed.building,
Expand All @@ -96,20 +105,21 @@ export default class LocationField extends React.Component {
}
};

tryParseLocationInput = (string) => {
tryParseLocationInput = (str) => {
let name = str;
const result = { isOlin: false, building: null, room: null };

if (string && string.length > 0) {
if (name && name.length > 0) {
// We don't care about case
string = string.toLowerCase();
name = name.toLowerCase();

// Define regular expressions to use when searching string
const buildingRegex = /^\D+/;
const roomRegex = /\d+/;
const suffixRegex = /\D*$/;

// Try to determine Olin building
let buildingString = buildingRegex.exec(string);
let buildingString = buildingRegex.exec(name);
if (buildingString && buildingString.length > 0) {
buildingString = buildingString[0].trim();

Expand Down Expand Up @@ -204,15 +214,15 @@ export default class LocationField extends React.Component {
}

// Try to determine Olin room number
const roomString = roomRegex.exec(string);
const roomString = roomRegex.exec(name);
if (roomString && roomString.length > 0) {
result.room = roomString[0].trim();
}

// Try to determine Olin room suffix (optional)
let suffixString = suffixRegex.exec(string);
if (suffixString && suffixString.length > 0) {
suffixString = suffixString[0];
const suffixMatch = suffixRegex.exec(name);
if (suffixMatch && suffixMatch.length > 0) {
const suffixString = suffixMatch[0];
// Just return if the regex didn't find anything
if (suffixString !== null && suffixString.length > 0) {
// The regex found something, so let's parse it
Expand All @@ -236,16 +246,6 @@ export default class LocationField extends React.Component {
return result;
};

static stringMatches(string, substrings) {
string = string.trim();
for (let i = 0; i < substrings.length; ++i) {
if (string === substrings[i]) {
return true;
}
}
return false;
}

render() {
// let svgSrc = (this.state.isOlin) ? '/assets/olin-o.svg' : '/assets/olin-o-slash.svg';
// let oTooltip = (this.state.isOlin) ? 'Recognized Olin location' : 'Location not at Olin';
Expand Down

0 comments on commit 4bd6f63

Please sign in to comment.