From 5c7489c965529d72a074fcf470dafebe515ba4c7 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 24 Aug 2017 13:17:22 -0700 Subject: [PATCH] Added eslint --- .eslintrc | 75 ++++++++++++++++++-------------- javascript/components/MapView.js | 44 ++++++++++++++++--- javascript/utils/index.js | 17 +++----- package.json | 9 ++-- 4 files changed, 90 insertions(+), 55 deletions(-) diff --git a/.eslintrc b/.eslintrc index 89742d6..40445b3 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,41 +1,50 @@ { "parser": "babel-eslint", - "extends": "eslint:recommended", "env": { + "es6": true, "browser": true, - "node": true, - "es6": true + "jest": true + }, + "parserOptions": { + "sourceType": "module", + "ecmaFeatures": { + "jsx": true + } + }, + "extends": ["eslint:recommended"], + "plugins": ["react", "import"], + "settings": { + "import/core-modules": [ + "react", "react-native", "prop-types" + ] }, - "plugins": [ - "react", - "react-native" - ], - "globals": { }, "rules": { - "camelcase": [0], - "comma-spacing": [0], - "consistent-return": [0], - "curly": [0], - "eol-last": [0], - "key-spacing": [0], - "new-cap": [0], - "no-mixed-requires": [0], - "no-redeclare": [2], - "no-underscore-dangle": [0], - "no-use-before-define": [0], - "quotes": [2, "single"], - "react/jsx-uses-react": [2], - "react/jsx-uses-vars": [2], - "react/no-multi-comp": 2, - "react/no-unknown-property": [2], - "react/prop-types": 2, - "react/require-extension": [2, { "extensions": [".js", ".jsx"] }], - "react/wrap-multilines": [2], - "react-native/no-unused-styles": 2, - "react-native/split-platform-components": 2, - "react-native/no-inline-styles": 2, - "react-native/no-color-literals": 2, - "strict": [0], - "valid-typeof": 2 + "comma-dangle": ["error", "always-multiline"], + "no-console": ["error", { allow: ["warn", "error"] }], + "semi": ["error", "always"], + "space-before-function-paren": ["error", "always"], + + "react/jsx-no-duplicate-props": ["error"], + "react/jsx-no-undef": ["error"], + "react/jsx-uses-react": ["error"], + "react/jsx-uses-vars": ["error"], + "react/no-danger": ["error"], + "react/no-deprecated": ["error"], + "react/no-direct-mutation-state": ["error"], + "react/no-unknown-property": ["error"], + "react/prefer-es6-class": ["error", "always"], + "react/prop-types": ["error"], + "react/react-in-jsx-scope": ["error"], + "react/require-render-return": ["error"], + + "import/default": ["error"], + "import/export": ["error"], + "import/named": ["error"], + "import/newline-after-import": ["error"], + "import/no-duplicates": ["error"], + "import/no-dynamic-require": ["error"], + "import/no-unresolved": ["error"], + "import/no-webpack-loader-syntax": ["error"], + "import/prefer-default-export": ["error"] } } diff --git a/javascript/components/MapView.js b/javascript/components/MapView.js index 5fa7bf7..7ae82d5 100644 --- a/javascript/components/MapView.js +++ b/javascript/components/MapView.js @@ -6,26 +6,56 @@ const RCTMGLMapView = requireNativeComponent('RCTMGLMapView', MapView); const DEFAULT_CENTER_COORDINATE = { type: 'Point', - coordinates: [-77.036086, 38.910233] -} + coordinates: [-77.036086, 38.910233], +}; +/** + * MapView backed by Mapbox Native GL + */ class MapView extends React.Component { static StyleURL = { Street: 'mapbox-streets', Dark: 'mapbox-dark', Light: 'mapbox-light', Outdoors: 'mapbox-outdoors', - Satellite: 'mapbox-satellite' - } + Satellite: 'mapbox-satellite', + }; static propTypes = { + /** + * Animates changes between pitch and bearing + */ animated: PropTypes.bool, + + /** + * Initial center coordinate on map + */ centerCoordinate: PropTypes.object, + + /** + * Initial heading on map + */ heading: PropTypes.number, - ptich: PropTypes.number, + + /** + * Initial pitch on map + */ + pitch: PropTypes.number, + + /** + * Style for wrapping React Native View + */ style: PropTypes.any, + + /** + * Style URL for map + */ styleURL: PropTypes.string, - zoomLevel: PropTypes.number + + /** + * Initial zoom level of map + */ + zoomLevel: PropTypes.number, }; static defaultProps = { @@ -34,7 +64,7 @@ class MapView extends React.Component { heading: 0, pitch: 0, zoomLevel: 16, - styleURL: MapView.StyleURL.Street + styleURL: MapView.StyleURL.Street, }; render () { diff --git a/javascript/utils/index.js b/javascript/utils/index.js index ce4eb6f..bebc203 100644 --- a/javascript/utils/index.js +++ b/javascript/utils/index.js @@ -2,19 +2,15 @@ import { NativeModules, findNodeHandle, Platform, - requireNativeComponent, } from 'react-native'; -const LOG_TAG = '[ReactNativeMapboxNavigationUtils]'; - export const IS_ANDROID = Platform.OS === 'android'; -export function runNativeCommand(module, name, nativeRef, args = []) { +export function runNativeCommand (module, name, nativeRef, args = []) { // android native command - const managerInstance = getManagerInstance(module) + const managerInstance = getManagerInstance(module); if (!managerInstance) { - console.log(LOG_TAG, `Could not find ${module}`); - return; + throw new Error(`Could not find ${module}`); } // get react tag so we can find, this component on the otherside @@ -31,16 +27,15 @@ export function runNativeCommand(module, name, nativeRef, args = []) { } // ios native command - const method = managerInstance[name] + const method = managerInstance[name]; if (!method) { - console.log(LOG_TAG, `Could not find method ${name} on module ${module}`); - return; + throw new Error(`Could not find method ${name} on module ${module}`); } method(handle, ...args); } -function getManagerInstance(module) { +function getManagerInstance (module) { const obj = IS_ANDROID ? NativeModules.UIManager : NativeModules; return obj[module]; } diff --git a/package.json b/package.json index f87ecf7..1634ecb 100644 --- a/package.json +++ b/package.json @@ -29,14 +29,15 @@ "docs:generate": "npm run docs:parse && npm run docs:build:md", "preinstall": "npm run fetch:ios:sdk", "test": "npm run lint", - "lint": "eslint --no-eslintrc -c .eslintrc index.js example.js" + "lint": "./node_modules/eslint/bin/eslint.js ./javascript/**", + "lint:fix": "npm run lint -- --fix" }, "devDependencies": { "babel-eslint": "^6.1.2", - "eslint": "^3.1.1", + "eslint": "^3.19.0", "eslint-config-strict-react": "^8.0.1", - "eslint-plugin-react": "^5.2.2", - "eslint-plugin-react-native": "1.1.0" + "eslint-plugin-import": "^2.7.0", + "eslint-plugin-react": "^5.2.2" }, "dependencies": { "lodash": "^4.13.1"