Skip to content

Commit

Permalink
feat(lint): simplify lint setup (rnmapbox#585)
Browse files Browse the repository at this point in the history
* Upgrade eslint -> 6.8.0

* Remove eslintrc from example dir

* Use lint script in package

* Lint files

Resolve linting errors
  • Loading branch information
ferdicus authored and kristfal committed Dec 29, 2019
1 parent 254c51d commit c675b05
Show file tree
Hide file tree
Showing 44 changed files with 168 additions and 201 deletions.
95 changes: 46 additions & 49 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,93 +1,90 @@
module.exports = {
"parser": "babel-eslint",
"plugins": [
"react",
"react-native",
"prettier",
"fp",
"flowtype",
],
"env": {
"jest": true
parser: "babel-eslint",
plugins: ["react", "react-native", "prettier", "fp", "flowtype"],
env: {
jest: true
},
"settings": {
"react": {
"version": require('./package.json').dependencies.react,
settings: {
react: {
version: require("./package.json").dependencies.react
},
"import/resolver": {
"node": {
"extensions": [
".js",
".jsx"
]
node: {
extensions: [".js", ".jsx"]
}
},
"react": {
"pragma": "React",
"version": "16.6.1",
"flowVersion": "0.87"
react: {
pragma: "React",
version: "16.6.1",
flowVersion: "0.87"
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true,
"modules": true
parserOptions: {
ecmaFeatures: {
jsx: true,
modules: true
}
}
},
"globals": {
"fetch": true,
"FormData": true,
"requestAnimationFrame": true,
"cancelAnimationFrame": true,
"WebSocket": true,
"__DEV__": true,
"window": true,
"document": true,
"navigator": true,
"XMLSerializer": true,
globals: {
fetch: true,
FormData: true,
requestAnimationFrame: true,
cancelAnimationFrame: true,
WebSocket: true,
__DEV__: true,
window: true,
document: true,
navigator: true,
XMLSerializer: true
},
"extends": [
extends: [
"eslint:recommended",
"plugin:react/recommended",
"airbnb-base",
"prettier",
"plugin:flowtype/recommended"
],
"rules": {
rules: {
"react/no-deprecated": "warn",
"react/no-string-refs": "warn",
"import/named": [2],
"import/no-named-default": [0],
"import/order": ["error", { "groups": ["builtin", "external", "parent", "sibling", "index"], "newlines-between": "always" }],
"import/order": [
"error",
{
groups: ["builtin", "external", "parent", "sibling", "index"],
"newlines-between": "always"
}
],
"import/exports-last": [0],
"import/no-useless-path-segments": [2],
"camelcase": [0],
camelcase: [0],
"no-console": [0],
"import/prefer-default-export": "off",
"jsx-a11y/href-no-hash": "off",
"react/prop-types": [2],
"quotes": [2, "single"],
quotes: [2, "single"],
"eol-last": [0],
"no-continue": [1],
"class-methods-use-this": [1],
"no-bitwise": [1],
"prefer-destructuring": [1],
"consistent-return": [1],
"no-warning-comments": [2],
"no-warning-comments": [1],
"no-mixed-requires": [0],
"no-return-assign": 0,
"no-underscore-dangle": [0],
"no-await-in-loop": 0,
"no-restricted-syntax": 0,
"no-use-before-define": ["error", { "functions": false }],
"no-unused-expressions": ["error", { "allowTaggedTemplates": true }],
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"no-use-before-define": ["error", { functions: false }],
"no-unused-expressions": ["error", { allowTaggedTemplates: true }],
"no-plusplus": ["error", { allowForLoopAfterthoughts: true }],
"prettier/prettier": [
"error",
{
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": false
singleQuote: true,
trailingComma: "all",
bracketSpacing: false
}
],
"fp/no-mutating-methods": "warn"
Expand Down
65 changes: 30 additions & 35 deletions __tests__/components/UserLocation.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import React from "react";
import {
render,
fireEvent,
flushMicrotasksQueue
} from "react-native-testing-library";
import React from 'react';
import {render, fireEvent} from 'react-native-testing-library';

import UserLocation from "../../javascript/components/UserLocation";
import ShapeSource from "../../javascript/components/ShapeSource";
import CircleLayer from "../../javascript/components/CircleLayer";

import locationManager from "../../javascript/modules/location/locationManager";
import UserLocation from '../../javascript/components/UserLocation';
import ShapeSource from '../../javascript/components/ShapeSource';
import CircleLayer from '../../javascript/components/CircleLayer';
import locationManager from '../../javascript/modules/location/locationManager';

const position = {
coords: {
Expand All @@ -18,25 +13,25 @@ const position = {
heading: 251.5358428955078,
latitude: 51.5462244,
longitude: 4.1036916,
speed: 0.08543474227190018
speed: 0.08543474227190018,
},
timestamp: 1573730357879
timestamp: 1573730357879,
};

describe("UserLocation", () => {
describe('UserLocation', () => {
beforeEach(() => {
jest.spyOn(locationManager, "start").mockImplementation(jest.fn());
jest.spyOn(locationManager, 'start').mockImplementation(jest.fn());
jest
.spyOn(locationManager, "getLastKnownLocation")
.spyOn(locationManager, 'getLastKnownLocation')
.mockImplementation(() => position);
});

afterEach(() => {
jest.restoreAllMocks();
});

test("renders with CircleLayers by default", done => {
const { getAllByType } = render(<UserLocation />);
test('renders with CircleLayers by default', done => {
const {getAllByType} = render(<UserLocation />);

setTimeout(() => {
const shapeSource = getAllByType(ShapeSource);
Expand All @@ -48,8 +43,8 @@ describe("UserLocation", () => {
});
});

test("does not render with visible set to false", done => {
const { queryByType } = render(<UserLocation visible={false} />);
test('does not render with visible set to false', done => {
const {queryByType} = render(<UserLocation visible={false} />);

setTimeout(() => {
const shapeSource = queryByType(ShapeSource);
Expand All @@ -61,22 +56,22 @@ describe("UserLocation", () => {
});
});

test("renders with CustomChild when provided", done => {
test('renders with CustomChild when provided', done => {
const circleLayerProps = {
key: "testUserLocationCircle",
id: "testUserLocationCircle",
key: 'testUserLocationCircle',
id: 'testUserLocationCircle',
style: {
circleRadius: 5,
circleColor: "#ccc",
circleColor: '#ccc',
circleOpacity: 1,
circlePitchAlignment: "map"
}
circlePitchAlignment: 'map',
},
};

const { queryByType, queryAllByType } = render(
const {queryByType, queryAllByType} = render(
<UserLocation>
<CircleLayer {...circleLayerProps} />
</UserLocation>
</UserLocation>,
);

setTimeout(() => {
Expand All @@ -92,7 +87,7 @@ describe("UserLocation", () => {
});
});

test("calls onUpdate callback when new location is received", () => {
test('calls onUpdate callback when new location is received', () => {
const onUpdateCallback = jest.fn();

render(<UserLocation onUpdate={onUpdateCallback} />);
Expand All @@ -104,22 +99,22 @@ describe("UserLocation", () => {
heading: 251.5358428955078,
latitude: 51.5462244,
longitude: 4.1036916,
speed: 0.08543474227190018
speed: 0.08543474227190018,
},
timestamp: 1573730357879
timestamp: 1573730357879,
});

expect(onUpdateCallback).toHaveBeenCalled();
});

test("calls onPress callback when location icon is pressed", () => {
test('calls onPress callback when location icon is pressed', () => {
const onPressCallback = jest.fn();

const { queryByType } = render(<UserLocation onPress={onPressCallback} />);
const {queryByType} = render(<UserLocation onPress={onPressCallback} />);

const shapeSource = queryByType(ShapeSource);
fireEvent(shapeSource, "onPress");
fireEvent(shapeSource, "onPress");
fireEvent(shapeSource, 'onPress');
fireEvent(shapeSource, 'onPress');
expect(onPressCallback).toHaveBeenCalledTimes(2);
});
});
4 changes: 0 additions & 4 deletions example/.eslintrc.js

This file was deleted.

5 changes: 3 additions & 2 deletions example/__tests__/App-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

import 'react-native';
import React from 'react';
import App from '../App';
import renderer from 'react-test-renderer';

import App from '../App'; // eslint-disable-line import/no-unresolved

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';

it('renders correctly', () => {
renderer.create(<App />);
Expand Down
1 change: 1 addition & 0 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import {AppRegistry} from 'react-native';

import App from './src/App';
import {name as appName} from './app.json';

Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@babel/runtime": "^7.6.2",
"@react-native-community/eslint-config": "^0.0.5",
"babel-jest": "^24.9.0",
"eslint": "^6.4.0",
"eslint": "^6.8.0",
"jest": "^24.9.0",
"jetifier": "^1.6.4",
"metro-react-native-babel-preset": "^0.56.0",
Expand Down
1 change: 1 addition & 0 deletions example/scripts/set_access_token.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ if (!accessToken) {
process.exit(1);
}

// eslint-disable-next-line no-new-wrappers
const fileContents = `{ "accessToken": "${new String(accessToken).trim()}" }`;
fs.writeFileSync(path.join('./', 'env.json'), fileContents);
42 changes: 33 additions & 9 deletions example/scripts/watch_rngl.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
const path = require('path');

// eslint-disable-next-line import/no-extraneous-dependencies
const fs = require('fs-extra');

const RNGL_DIR = path.join('..');
const RNGL_EXAMPLE_DIR = path.join('node_modules', '@react-native-mapbox-gl', 'maps');
const RNGL_EXAMPLE_DIR = path.join(
'node_modules',
'@react-native-mapbox-gl',
'maps',
);

function copyFile(source, dest) {
return new Promise((resolve, reject) => {
fs.copy(source, dest, (err) => {
fs.copy(source, dest, err => {
if (err) {
return reject(err);
}
Expand All @@ -15,25 +21,43 @@ function copyFile(source, dest) {
});
}

async function main () {
async function main() {
try {
console.log('Copying javascript');
await copyFile(path.join(RNGL_EXAMPLE_DIR, 'javascript'), path.join(RNGL_DIR, 'javascript'));
await copyFile(
path.join(RNGL_EXAMPLE_DIR, 'javascript'),
path.join(RNGL_DIR, 'javascript'),
);

console.log('Copying typescript');
await copyFile(path.join(RNGL_EXAMPLE_DIR, 'index.d.ts'), path.join(RNGL_DIR, 'index.d.ts'));
await copyFile(
path.join(RNGL_EXAMPLE_DIR, 'index.d.ts'),
path.join(RNGL_DIR, 'index.d.ts'),
);

console.log('Copying java');
await copyFile(path.join(RNGL_EXAMPLE_DIR, 'android', 'rctmgl', 'src'), path.join(RNGL_DIR, 'android', 'rctmgl', 'src'));
await copyFile(
path.join(RNGL_EXAMPLE_DIR, 'android', 'rctmgl', 'src'),
path.join(RNGL_DIR, 'android', 'rctmgl', 'src'),
);

console.log('Copying gradle file');
await copyFile(path.join(RNGL_EXAMPLE_DIR, 'android', 'rctmgl', 'build.gradle'), path.join(RNGL_DIR, 'android', 'rctmgl', 'build.gradle'));
await copyFile(
path.join(RNGL_EXAMPLE_DIR, 'android', 'rctmgl', 'build.gradle'),
path.join(RNGL_DIR, 'android', 'rctmgl', 'build.gradle'),
);

console.log('Copying objc');
await copyFile(path.join(RNGL_EXAMPLE_DIR, 'ios', 'RCTMGL'), path.join(RNGL_DIR, 'ios', 'RCTMGL'));
await copyFile(
path.join(RNGL_EXAMPLE_DIR, 'ios', 'RCTMGL'),
path.join(RNGL_DIR, 'ios', 'RCTMGL'),
);

console.log('Copying xcode project');
await copyFile(path.join(RNGL_EXAMPLE_DIR, 'ios', 'RCTMGL.xcodeproj'), path.join(RNGL_DIR, 'ios', 'RCTMGL.xcodeproj'));
await copyFile(
path.join(RNGL_EXAMPLE_DIR, 'ios', 'RCTMGL.xcodeproj'),
path.join(RNGL_DIR, 'ios', 'RCTMGL.xcodeproj'),
);
} catch (e) {
console.log(e);
}
Expand Down
3 changes: 1 addition & 2 deletions example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class App extends React.Component {
return (
<SafeAreaView
style={[sheet.matchParent, {backgroundColor: colors.primary.blue}]}
forceInset={{top: 'always'}}
>
forceInset={{top: 'always'}}>
<View style={sheet.matchParent}>
<Text style={styles.noPermissionsText}>
You need to accept location permissions in order to use this
Expand Down
Loading

0 comments on commit c675b05

Please sign in to comment.