Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint & Prettier - Added #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
env: {
browser: true,
commonjs: false,
es6: true,
node: true,
jest: true,
},
extends: ["plugin:react/recommended", "eslint:recommended"],
parser: "babel-eslint",
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
},
plugins: ["react"],
rules: {
"arrow-body-style": 2,
semi: ["error", "always"],
quotes: ["error", "double"],
"prefer-const": 1,
},
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ build/Release
# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules
.DS_Store
16 changes: 5 additions & 11 deletions TimeAgo.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// @flow
import React, { Component } from "react";
import { View, Text } from "react-native";
import { Text } from "react-native";
import moment from "moment";

export default class TimeAgo extends Component {
props: {
time: string,
interval?: number,
hideAgo?: boolean
hideAgo?: boolean,
};
state: { timer: null | number } = { timer: null };

static defaultProps = {
hideAgo: false,
interval: 60000
interval: 60000,
};

componentDidMount() {
Expand All @@ -22,9 +22,7 @@ export default class TimeAgo extends Component {

createTimer = () => {
this.setState({
timer: setTimeout(() => {
this.update();
}, this.props.interval)
timer: setTimeout(() => this.update(), this.props.interval),
});
};

Expand All @@ -39,10 +37,6 @@ export default class TimeAgo extends Component {

render() {
const { time, hideAgo } = this.props;
return (
<Text {...this.props}>
{moment(time).fromNow(hideAgo)}
</Text>
);
return <Text {...this.props}>{moment(time).fromNow(hideAgo)}</Text>;
}
}
28 changes: 14 additions & 14 deletions __tests__/TimeAgo.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React from 'react'
import { Text } from 'react-native'
import TestRenderer from 'react-test-renderer'
import moment from 'moment'
import TimeAgo from '../TimeAgo'
import React from "react";
import { Text } from "react-native";
import TestRenderer from "react-test-renderer";
import moment from "moment";
import TimeAgo from "../TimeAgo";

describe('TimeAgo', () => {
test('Renders', () => {
const timestamp = moment().subtract(10, 'days')
describe("TimeAgo", () => {
test("Renders", () => {
const timestamp = moment().subtract(10, "days");
const renderer = TestRenderer.create(
<TimeAgo time={timestamp} />
)
const instance = renderer.root
expect(instance.findByType(Text).props.children).toEqual('10 days ago')
renderer.unmount()
})
})
);
const instance = renderer.root;
expect(instance.findByType(Text).props.children).toEqual("10 days ago");
renderer.unmount();
});
});
6 changes: 3 additions & 3 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
"presets": ["module:metro-react-native-babel-preset"],
"plugins": ["@babel/proposal-class-properties"]
}
presets: ["module:metro-react-native-babel-preset"],
plugins: ["@babel/proposal-class-properties"],
};
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"main": "TimeAgo.js",
"typings": "./index.d.ts",
"scripts": {
"test": "jest --verbose"
"test": "jest --verbose",
"lint": "eslint *.js",
"prettier-write": "prettier --write \"*.js\"",
"prettier-check": "prettier --check \"*.js\""
},
"keywords": [
"react-native",
Expand All @@ -32,13 +35,18 @@
"license": "ISC",
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.7.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^24.9.0",
"babel-preset-react-native": "^4.0.0",
"eslint": "^6.8.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-react": "^7.19.0",
"jest": "^24.9.0",
"jest-cli": "^24.9.0",
"jest-react-native": "^18.0.0",
"metro-react-native-babel-preset": "^0.57.0",
"moment": "^2.19.1",
"prettier": "^2.0.2",
"prop-types": "^15.6.0",
"react": "^16.0.0",
"react-native": "^0.61.4",
Expand Down