diff --git a/.eslintrc.js b/.eslintrc.js
index de183ee..ea33d35 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -4,7 +4,11 @@ module.exports = {
"browser": true,
"es6": true
},
- "extends": "eslint:recommended",
+ "extends": [
+ "eslint:recommended",
+ "plugin:flowtype/recommended",
+ "plugin:react/recommended"
+ ],
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
@@ -16,21 +20,118 @@ module.exports = {
"react", "flowtype"
],
"rules": {
- "indent": ["error", 2],
- "linebreak-style": ["error", "unix"],
- "quotes": ["error","double"],
- "semi": ["error","always"],
+ // possible errors
+ "getter-return": "error",
+ "no-extra-parens": ["error", "functions"],
+ "no-template-curly-in-string": "error",
+ "valid-jsdoc": "error",
+
+ // best practices
+ "accessor-pairs": "error",
+ "array-callback-return": "error",
+ "block-scoped-var": "error",
+ "consistent-return": ["error", { "treatUndefinedAsUnspecified": true }],
+ "curly": "error",
+ "default-case": ["error", { "commentPattern": "^skip\\sdefault" }],
+ "dot-location": ["error", "property"],
+ "eqeqeq": ["error", "smart"],
+ "no-alert": "error",
+ "no-caller": "error",
+ "no-eval": "error",
+ "no-extend-native": "error",
+ "no-extra-label": "error",
+ "no-floating-decimal": "error",
+ "no-implicit-coercion": "error",
+ "no-implied-eval": "error",
+ "no-invalid-this": "error",
+ "no-iterator": "error",
+ "no-loop-func": "error",
+ "no-multi-spaces": "warn",
+ "no-multi-str": "error",
+ "no-new": "warn",
+ "no-new-func": "error",
+ "no-new-wrappers": "error",
+ "no-octal-escape": "error",
+ "no-param-reassign": "error",
+ "no-proto": "error",
+ "no-return-assign": "error",
+ "no-return-await": "error",
+ "no-script-url": "error",
+ "no-self-compare": "error",
+ "no-sequences": "error",
+ "no-throw-literal": "error",
+ "no-unmodified-loop-condition": "error",
+ "no-unused-expressions": ["error", {
+ "allowShortCircuit": true,
+ "allowTernary": true
+ }],
+ "no-useless-call": "warn",
+ "no-useless-return": "error",
+ "no-warning-comments": ["warn", { "terms": ["todo", "fixme", "error", "bug"] }],
+ "no-with": "error",
+ "prefer-promise-reject-errors": "error",
+ "radix": "warn",
+ "require-await": "warn",
+ "vars-on-top": "warn",
+ "yoda": "warn",
+
+ // variables
+ "init-declarations": ["error", "always"],
"no-unused-vars": ["error", { "varsIgnorePattern": "^_", "argsIgnorePattern": "^_" }],
+ "no-catch-shadow": "error",
+ "no-label-var": "error",
+ "no-shadow": "error",
+ "no-shadow-restricted-names": "error",
+ "no-undef-init": "error",
+ "no-undefined": "error",
+ "no-use-before-define": "error",
- "react/jsx-uses-react": 2,
- "react/jsx-uses-vars": 2,
- "react/react-in-jsx-scope": "error",
+ // stylistic issues
+ "array-bracket-spacing": ["error", "never"],
+ "block-spacing": ["error", "always"],
+ "brace-style": ["warn", "1tbs"],
+ "camelcase": ["warn", { properties: "always" }],
+ "comma-dangle": ["error", {
+ "arrays": "never",
+ "objects": "never",
+ "imports": "never",
+ "exports": "never",
+ "functions": "never"
+ }],
+ "comma-spacing": "warn",
+ "computed-property-spacing": ["warn", "never"],
+ "eol-last": ["warn", "always"],
+ "func-call-spacing": ["warn", "never"],
+ "func-names": ["warn", "as-needed"],
+ "indent": ["warn", 2],
+ "jsx-quotes": "warn",
+ "key-spacing": "warn",
+ "keyword-spacing": "warn",
+ "linebreak-style": ["error", "unix"],
+ "lines-around-comment": "warn",
+ "lines-between-class-members": ["warn", "always"],
+ "max-len": "error",
+ "max-nested-callbacks": ["error", 5],
+ "max-statements-per-line": "error",
+ "multiline-comment-style": ["error", "starred-block"],
+ "new-parens": "error",
+ "no-array-constructor": "error",
+ "no-trailing-spaces": "error",
+ "no-unneeded-ternary": "warn",
+ "no-whitespace-before-property": "error",
+ "one-var": ["error", "never"],
+ "semi": ["error", "always"],
+ "semi-spacing": "error",
+ "semi-style": "error",
+ "space-before-blocks": "error",
+ "quotes": ["error", "double"],
- "flowtype/define-flow-type": 2,
- "flowtype/boolean-style": "error",
- "flowtype/generic-spacing": ["error", "never"],
+ // react
+ "react/prop-types": "off",
+ "react/display-name": "off",
+
+ // flow
"flowtype/no-dupe-keys": "error",
- "flowtype/union-intersection-spacing": ["error", "always"],
"flowtype/no-weak-types": "warn",
"flowtype/require-variable-type": "warn"
}
diff --git a/package.json b/package.json
index 9b02b87..8dbdb02 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"production-build": "webpack --bail --config webpack.prod.js",
"watch": "webpack-dev-server --open --config webpack.dev.js",
"travis": "yarn lint && yarn build && yarn production-build",
- "lint": "yarn eslint -- --ext js --ext jsx src/",
+ "lint": "eslint -- --ext js --ext jsx src/",
"precommit": "yarn lint"
},
"dependencies": {
diff --git a/src/UiItems.js b/src/UiItems.js
index b8746d0..10552f8 100644
--- a/src/UiItems.js
+++ b/src/UiItems.js
@@ -14,23 +14,36 @@ import {
ListItemIcon,
ListItemSecondaryAction,
ListItemText,
- ListSubheader,
+ ListSubheader
} from "material-ui/List";
import Button from "material-ui/Button";
const enabled = (props: ControlUI, state: State) => {
- if (props.enableCondition == null) return true;
- else {
+ if (props.enableCondition == null) {
+ return true;
+ } else {
const val = state.values[props.topic];
return props.enableCondition(
- val.internal == null ? val.actual : val.internal, val.actual, R.map(x => x.internal == null ?
- x.actual : x.internal, state.values == null ? {} : state.values));
+ val.internal == null ? val.actual : val.internal, val.actual,
+ R.map(x => x.internal == null ? x.actual
+ : x.internal, state.values == null ? {} : state.values));
}
};
const getValue = (topic: string, val: string) =>
Config.topics[topic].values[val];
+const renderIcon = (icon: string) => {
+ if (icon != null) {
+ return (
+
+
+
+ );
+ }
+ return null;
+};
+
export const onSwitch = (topic: string, props: ControlUI, state: State) =>
(x, toggled: boolean) => {
if (state.mqtt != null) {
@@ -53,11 +66,11 @@ export const isToggled = (state: State, props: ControlUI) => {
export const toggle = (state: State, props: ControlUI) => {
return (
- {props.icon && }
+ {renderIcon(props.icon)}
@@ -77,10 +90,11 @@ const dropDownItem = (topic: string) => (text: string, key: string) => (
);
export const dropDown = (state: State, props: ControlUI) => {
- const id = `${props.topic}.${Object.keys(props.options).reduce((v,r) => v + "." + r)}`;
+ const id = `${props.topic}.${Object.keys(props.options)
+ .reduce((v, r) => v + "." + r)}`;
return (
- {props.icon && }
+ {renderIcon(props.icon)}
{props.text}