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

chore: Add typescript support #874

Open
wants to merge 3 commits into
base: master
from
Open
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Prev

chore: Add typescript support

Add infrastructure for typescript. Move App.js -> App.tsx as an example
  • Loading branch information
G2Jose committed May 5, 2019
commit d6d4b56e6d1f98ad72fb23d44110eff48da4dfb5
@@ -1,6 +1,13 @@
module.exports = {
extends: 'eslint-config-airbnb',
plugins: ['jsx-a11y', 'import', 'react', 'react-native', 'flowtype'],
plugins: [
'jsx-a11y',
'import',
'react',
'react-native',
'flowtype',
'@typescript-eslint',
],
parser: 'babel-eslint',
env: {
browser: true,
@@ -92,7 +99,7 @@ module.exports = {
'react/jsx-filename-extension': [
'error',
{
extensions: ['.js', '.jsx'],
extensions: ['.js', '.jsx', '.tsx'],
},
],
'react/jsx-indent': 'off',
@@ -139,4 +146,15 @@ module.exports = {
},
],
},
overrides: [
{
files: ['**/*.ts', '**/*.tsx'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
},
},
],
};
@@ -65,3 +65,6 @@ haste-map-react-native-packager*
.idea

coverage

# Jest
.jest/
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import styled from 'styled-components';
import styled from 'styled-components/native';
import {
AppRegistry,
LayoutAnimation,
@@ -9,6 +9,7 @@ import {
} from 'react-native';
import codePush from 'react-native-code-push';
import { PersistGate } from 'redux-persist/integration/react';
import { NavigationRoute, NavigationParams } from 'react-navigation';
import { colors, getStatusBarConfig } from 'config';
import { getCurrentLocale, configureLocale } from 'utils';
import { GitPoint } from './routes';
@@ -30,40 +31,42 @@ if (console) {
console.disableYellowBox = true; // eslint-disable-line no-console
}

class App extends Component {
static async initLocale() {
const locale = await getCurrentLocale();
type State = {
rehydrated: boolean;
};

configureLocale(locale);
}
type Props = {};

constructor() {
super();
class App extends Component<Props, State> {
constructor(props: Props) {
super(props);

this.state = {
rehydrated: false,
};
this.statusBarHandler = this.statusBarHandler.bind(this);
}

componentWillMount() {
this.constructor.initLocale();
this.statusBarHandler = this.statusBarHandler.bind(this);
}

componentDidMount() {
async componentDidMount() {
if (!__DEV__) {
codePush.sync({
updateDialog: false,
updateDialog: undefined,
installMode: codePush.InstallMode.IMMEDIATE,
});
}
const locale = await getCurrentLocale();

configureLocale(locale);
}

componentWillUpdate() {
LayoutAnimation.spring();
}

getCurrentRouteName(navigationState) {
getCurrentRouteName(
navigationState: NavigationRoute<NavigationParams>
): string | null {
if (!navigationState) {
return null;
}
@@ -76,7 +79,10 @@ class App extends Component {
return route.routeName;
}

statusBarHandler(prev, next) {
statusBarHandler(
prev: NavigationRoute<NavigationParams>,
next: NavigationRoute<NavigationParams>
) {
const routeName = this.getCurrentRouteName(next);

const { translucent, backgroundColor, barStyle } = getStatusBarConfig(
@@ -1 +1,2 @@
// eslint-disable-next-line import/no-unresolved, import/extensions
import './App';
@@ -19,12 +19,12 @@
"link": "react-native link",
"ios": "react-native run-ios",
"android": "react-native run-android",
"i18n:extract": "node ./scripts/extract-i18n.js && prettier --loglevel silent --write src/locale/**/*.js",
"i18n:extract": "node ./scripts/extract-i18n.js && prettier --loglevel silent --write src/locale/**/*.js src/locale/**/*.ts",
"commitmsg": "minicat $GIT_PARAMS | commitlint",
"precommit": "lint-staged",
"eslint": "eslint .",
"stylelint": "stylelint src/**/*.js",
"prettier": "prettier --write \"**/*.js\"",
"stylelint": "stylelint src/**/*.js src/**/*.ts src/**/*.tsx",
"prettier": "prettier --write \"**/*.js\" \"**/*.ts\" \"**/*.tsx\"",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage && cat ./coverage/lcov.info | coveralls",
@@ -46,7 +46,7 @@
"postinstall": "opencollective postinstall"
},
"lint-staged": {
"*.js": [
"*.{js,ts,tsx}": [
"prettier-eslint --write --list-different --eslint-config-path .eslintrc.js",
"git add"
]
@@ -103,6 +103,15 @@
},
"devDependencies": {
"@commitlint/cli": "^3.1.0",
"@types/jest": "^24.0.12",
"@types/react": "^16.8.16",
"@types/react-native": "^0.57.51",
"@types/react-navigation": "^3.0.6",
"@types/react-redux": "^7.0.8",
"@types/react-test-renderer": "^16.8.1",
"@types/styled-components": "^4.1.14",
"@typescript-eslint/eslint-plugin": "^1.7.0",
"@typescript-eslint/parser": "^1.7.0",
"all-contributors-cli": "^4.10.1",
"babel-eslint": "^10.0.1",
"babel-jest": "^22.4.3",
@@ -134,28 +143,45 @@
"lint-staged": "^3.2.6",
"minicat": "^1.0.0",
"opencollective": "^1.0.3",
"prettier": "^1.7.4",
"prettier": "^1.17.0",
"prettier-eslint-cli": "^4.7.1",
"react-dom": "16.3.0-alpha.1",
"react-native-cli": "^2.0.1",
"react-native-mock": "https://github.com/shqld/react-native-mock/tarball/master",
"react-native-typescript-transformer": "^1.2.12",
"react-test-renderer": "16.3.0-alpha.1",
"reactotron-react-native": "^1.14.0",
"reactotron-redux": "^1.13.0",
"recursive-keys": "^0.9.0",
"stylelint": "^8.2.0",
"stylelint-config-standard": "^18.0.0",
"stylelint-config-styled-components": "^0.1.1",
"stylelint-processor-styled-components": "^1.0.0"
"stylelint-processor-styled-components": "^1.0.0",
"ts-jest": "^24.0.2",
"typescript": "^3.4.5"
},
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\\.(js)$": "<rootDir>/node_modules/babel-jest",
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testMatch": [
"**/__tests__/tests/**/*.js"
"**/__tests__/tests/**/*.(js|ts|tsx)"
],
"setupFiles": [
"./testenv.js"
],
"testPathIgnorePatterns": [
"\\.snap$",
"<rootDir>/node_modules/"
],
"cacheDirectory": ".jest/cache",
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-navigation)"
],
@@ -31,6 +31,12 @@ const config = {
params: rnpm.params || [],
});
},
getTransformModulePath() {
return require.resolve('react-native-typescript-transformer');
},
getSourceExts() {
return ['ts', 'tsx'];
},
};

module.exports = config;
@@ -677,6 +677,7 @@ class Events extends Component {
}
}

export const EventsScreen = connect(mapStateToProps, mapDispatchToProps)(
Events
);
export const EventsScreen = connect(
mapStateToProps,
mapDispatchToProps
)(Events);
@@ -77,8 +77,8 @@ export const DiffBlocks = ({
deletedBlocks = deletions;
neutralBlocks = 5 - (addedBlocks + deletedBlocks);
} else {
addedBlocks = Math.floor(additions / linesChanged * 5);
deletedBlocks = Math.floor(deletions / linesChanged * 5);
addedBlocks = Math.floor((additions / linesChanged) * 5);
deletedBlocks = Math.floor((deletions / linesChanged) * 5);
neutralBlocks = 5 - (addedBlocks + deletedBlocks);
}

@@ -306,8 +306,7 @@ export class GithubHtmlView extends Component {
onLinkPress({ ...node, attribs: { href: node.attribs.src } })
}
>
[{node.attribs.alt}]
{'\n'}
[{node.attribs.alt}]{'\n'}
</Text>
);
}
@@ -180,14 +180,13 @@ export class IssueDescription extends Component {
/>

{!issue.pull_request ||
(issue.pull_request &&
!isPendingCheckMerge && (
<StateBadge
issue={issue}
isMerged={isMerged && issue.pull_request}
locale={locale}
/>
))}
(issue.pull_request && !isPendingCheckMerge && (
<StateBadge
issue={issue}
isMerged={isMerged && issue.pull_request}
locale={locale}
/>
))}
</HeaderContainer>

{issue.pull_request && (
@@ -209,42 +208,39 @@ export class IssueDescription extends Component {
</TouchableHighlight>
)}

{!isPendingDiff &&
(lineAdditions !== 0 || lineDeletions !== 0) && (
<DiffBlocks
additions={lineAdditions}
deletions={lineDeletions}
showNumbers
onPress={() =>
navigation.navigate('PullDiff', {
title: t('Diff', locale),
locale,
diff,
})
}
/>
)}
{!isPendingDiff && (lineAdditions !== 0 || lineDeletions !== 0) && (
<DiffBlocks
additions={lineAdditions}
deletions={lineDeletions}
showNumbers
onPress={() =>
navigation.navigate('PullDiff', {
title: t('Diff', locale),
locale,
diff,
})
}
/>
)}
</DiffBlocksContainer>
)}

{issue.labels &&
issue.labels.length > 0 && (
<LabelButtonGroup>
{this.renderLabelButtons(issue.labels)}
</LabelButtonGroup>
)}
{issue.assignees &&
issue.assignees.length > 0 && (
<AssigneesSection>
<MembersList
title={t('Assignees', locale)}
members={issue.assignees}
containerStyle={{ marginTop: 0, paddingTop: 0, paddingLeft: 0 }}
smallTitle
navigation={navigation}
/>
</AssigneesSection>
)}
{issue.labels && issue.labels.length > 0 && (
<LabelButtonGroup>
{this.renderLabelButtons(issue.labels)}
</LabelButtonGroup>
)}
{issue.assignees && issue.assignees.length > 0 && (
<AssigneesSection>
<MembersList
title={t('Assignees', locale)}
members={issue.assignees}
containerStyle={{ marginTop: 0, paddingTop: 0, paddingLeft: 0 }}
smallTitle
navigation={navigation}
/>
</AssigneesSection>
)}

{issue.pull_request &&
!isMerged &&
@@ -184,14 +184,11 @@ class PullDiff extends Component {
</Text>
)}

{!item.new &&
!item.deleted && (
<Text style={[styles.fileTitle, styles.codeStyle]}>
{item.from === item.to
? item.to
: `${item.from} \n${item.to}`}
</Text>
)}
{!item.new && !item.deleted && (
<Text style={[styles.fileTitle, styles.codeStyle]}>
{item.from === item.to ? item.to : `${item.from} \n${item.to}`}
</Text>
)}
</ScrollView>

{item.chunks.length > 0 && chunks}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.