Skip to content

Commit 7184b2d

Browse files
authored
NOJIRA Endra fra flow til typescript (navikt#426)
* NOJIRA Endra fra flow til typescript
1 parent 292f00c commit 7184b2d

File tree

110 files changed

+735
-853
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+735
-853
lines changed

.flowconfig

-29
This file was deleted.

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*.html text eol=lf
99
*.jsx text eol=lf
1010
*.js text eol=lf
11+
*.tsx text eol=lf
12+
*.ts text eol=lf
1113
*.css text eol=lf
1214
*.sass text eol=lf
1315
*.less text eol=lf

.sonarcloud.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Path to sources
22
sonar.sources=packages
3-
sonar.exclusions=**/assets/**,**/*.spec.jsx
3+
sonar.exclusions=**/assets/**,**/*.spec.*
44
#sonar.inclusions=**/assets/**,**/*.spec.jsx
55

66
# Path to tests
77
sonar.tests=packages
88
#sonar.test.exclusions=
9-
sonar.test.inclusions=**/*.spec.jsx
9+
sonar.test.inclusions=**/*.spec.*
1010

1111
# Source encoding
1212
sonar.sourceEncoding=UTF-8

@types/mock.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare module '*.svg'
2+
declare module '*.less'

babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = function(api) {
22
api.cache(true);
3-
const presets = ['@babel/react', ['@babel/env', { modules: false }], '@babel/flow'];
3+
const presets = ['@babel/react', ['@babel/env', { modules: false }], '@babel/typescript'];
44
const plugins = ['@babel/plugin-proposal-class-properties'];
55

66
return {

eslint/eslintrc.common.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ const config = {
1515
VERSION: ON,
1616
},
1717

18+
parser: '@typescript-eslint/parser',
19+
20+
plugins: ['@typescript-eslint'],
21+
1822
extends: [
1923
'airbnb',
20-
'plugin:flowtype/recommended',
21-
],
22-
23-
parser: 'babel-eslint',
24-
plugins: [
25-
'flowtype',
24+
'plugin:@typescript-eslint/recommended',
2625
],
2726

2827
parserOptions: {
@@ -38,9 +37,20 @@ const config = {
3837
'linebreak-style': OFF,
3938
'import/no-named-as-default': OFF,
4039
'max-len': [ERROR, 160],
40+
'react/require-default-props': OFF,
41+
'react/jsx-filename-extension': OFF,
42+
'no-undef': OFF,
4143

4244
// TODO (TOR) Ignorert inntil videre grunnet kost/nytte
4345
'jsx-a11y/anchor-is-valid': OFF,
46+
47+
'@typescript-eslint/no-unused-vars': ERROR,
48+
'@typescript-eslint/indent': OFF,
49+
50+
// TODO (TOR) Midlertidig utkommentert
51+
'@typescript-eslint/explicit-member-accessibility': OFF,
52+
'@typescript-eslint/explicit-function-return-type': OFF,
53+
'@typescript-eslint/no-explicit-any': OFF,
4454
},
4555
};
4656

eslint/eslintrc.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const config = {
1818
'no-unused-expressions': OFF,
1919
'no-debugger': ERROR,
2020
'no-console': ERROR,
21+
'import/no-extraneous-dependencies': OFF,
2122
},
2223
};
2324

eslint/eslintrc.test.watch.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const config = {
1717
rules: {
1818
'no-unused-expressions': OFF,
1919
'no-debugger': WARN,
20+
'import/no-extraneous-dependencies': OFF,
2021
},
2122
};
2223

package.json

+27-8
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
"url": "git+https://github.com/navikt/fpsak-frontend.git"
1212
},
1313
"scripts": {
14-
"test": "mochapack --webpack-config webpack/webpack.test.js \"packages/**/*.spec.jsx\"",
15-
"test:watch": "mochapack --watch --webpack-config webpack/webpack.test.watch.js \"packages/**/*.spec.jsx\"",
16-
"test:coverage": "nyc mochapack --webpack-config webpack/webpack.test.coverage.js \"packages/**/src/**/*.jsx\"",
14+
"test": "mochapack --webpack-config webpack/webpack.test.js \"packages/**/*.spec.*\"",
15+
"test:watch": "mochapack --watch --webpack-config webpack/webpack.test.watch.js \"packages/**/*.spec.*\"",
16+
"test:coverage": "nyc mochapack --webpack-config webpack/webpack.test.coverage.js \"packages/**/*.spec.*\"",
1717
"dev": "cross-env NODE_ENV=development node webpack/webpack.dev.server.js --config webpack/webpack.dev.js",
1818
"build": "cross-env NODE_ENV=production webpack --no-progress --colors --config webpack/webpack.prod.js",
1919
"postinstall": "yarn run build && yarn test && yarn run less:lint",
2020
"lerna": "lerna",
2121
"lerna:publish": "(lerna updated && lerna publish --cd-version patch --yes -m \"publish [ci skip]\") || echo \"Ingen endringer avslutter OK\"",
2222
"less:lint": "stylelint \"packages/**/*.less\"",
23+
"ts-check": "tsc --pretty",
2324
"doc": "react-asciidoc-generator ./packages/ -o ../../docs/generated/react.adoc --handlebar-template src/docs/asciidoc-template.handlebars",
2425
"docker:build": "docker build . -t fpfront -f ./docker/Dockerfile --build-arg HTTP_PROXY=$HTTP_PROXY --build-arg HTTPS_PROXY=$HTTP_PROXY",
2526
"docker:start": "yarn docker:stop; yarn docker:build; docker run -d --env-file=./docker/.env --name fpfront -p 443:9000 fpfront",
@@ -49,10 +50,26 @@
4950
"@babel/plugin-proposal-class-properties": "^7.3.4",
5051
"@babel/plugin-transform-runtime": "^7.3.4",
5152
"@babel/preset-env": "^7.3.4",
52-
"@babel/preset-flow": "^7.0.0",
5353
"@babel/preset-react": "^7.0.0",
54+
"@babel/preset-typescript": "^7.3.3",
5455
"@babel/register": "^7.0.0",
5556
"@commercetools/enzyme-extensions": "^4.0.0",
57+
"@types/chai": "^4.1.7",
58+
"@types/classnames": "^2.2.7",
59+
"@types/enzyme": "^3.9.0",
60+
"@types/enzyme-adapter-react-16": "^1.0.5",
61+
"@types/history": "^4.7.2",
62+
"@types/mocha": "^5.2.6",
63+
"@types/prop-types": "^15.7.0",
64+
"@types/react": "^16.8.7",
65+
"@types/react-collapse": "^4.0.2",
66+
"@types/react-dom": "^16.8.2",
67+
"@types/react-intl": "^2.3.17",
68+
"@types/react-redux": "^7.0.5",
69+
"@types/react-router-dom": "^4.3.1",
70+
"@types/sinon": "^7.0.10",
71+
"@typescript-eslint/eslint-plugin": "^1.4.2",
72+
"@typescript-eslint/parser": "^1.4.2",
5673
"axios-mock-adapter": "^1.16.0",
5774
"babel-eslint": "^10.0.1",
5875
"babel-loader": "^8.0.5",
@@ -66,13 +83,10 @@
6683
"eslint-config-import": "^0.13.0",
6784
"eslint-import-resolver-webpack": "^0.11.0",
6885
"eslint-loader": "^2.1.2",
69-
"eslint-plugin-flowtype": "^3.4.2",
7086
"eslint-plugin-import": "^2.16.0",
7187
"eslint-plugin-jsx-a11y": "^6.2.1",
7288
"eslint-plugin-react": "^7.12.4",
7389
"file-loader": "^3.0.1",
74-
"flow-bin": "^0.94.0",
75-
"flow-typed": "^2.5.1",
7690
"happypack": "^5.0.1",
7791
"html-webpack-plugin": "^3.2.0",
7892
"ignore-styles": "^5.0.1",
@@ -94,6 +108,7 @@
94108
"sinon-chai": "^3.2.0",
95109
"style-loader": "^0.23.1",
96110
"stylelint": "^9.10.1",
111+
"typescript": "^3.3.3333",
97112
"uglifyjs-webpack-plugin": "^2.1.0",
98113
"wait-on": "^3.2.0",
99114
"webpack": "^4.29.6",
@@ -115,10 +130,14 @@
115130
],
116131
"extension": [
117132
".jsx",
133+
".tsx",
134+
".ts",
118135
".es6"
119136
],
120137
"exclude": [
121-
"**/*.spec.jsx"
138+
"**/*.spec.jsx",
139+
"**/*.spec.tsx",
140+
"**/*.spec.ts"
122141
]
123142
}
124143
}

packages/error-api-redux/index.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* @flow */
21
import errorHandler from './src/ErrorHandler';
32

43
export default errorHandler;

packages/error-api-redux/src/ErrorFormatter.jsx

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
/* @flow */
21
import DefaultFormatter from './formatters/DefaultFormatter';
32
import RestTimeoutFormatter from './formatters/RestTimeoutFormatter';
43
import RestHaltedOrDelayedFormatter from './formatters/RestHaltedOrDelayedFormatter';
54

65
const defaultFormatter = new DefaultFormatter();
76
const formatters = [new RestTimeoutFormatter(), new RestHaltedOrDelayedFormatter(), defaultFormatter];
87

9-
type ErrorMessage = {
10-
type: string,
11-
}
12-
138
class ErrorFormatter {
14-
format = (errorMessages: ErrorMessage[], crashMessage?: string) => {
9+
format = (errorMessages, crashMessage) => {
1510
const allErrorMessages = [];
1611
if (crashMessage) {
1712
allErrorMessages.push(defaultFormatter.format(crashMessage));
1813
}
1914

2015
if (errorMessages.length > 0) {
2116
errorMessages
22-
.map((e: ErrorMessage) => {
17+
.map((e) => {
2318
const formatter = formatters.find(f => f.isOfType(e.type));
2419
return formatter ? formatter.format(e) : undefined;
2520
})

packages/error-api-redux/src/ErrorFormatter.spec.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* @flow */
21
import { expect } from 'chai';
32

43
import ErrorFormatter from './ErrorFormatter';

packages/error-api-redux/src/ErrorHandler.jsx

-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* @flow */
21
import { createSelector } from 'reselect';
32

43
import {
@@ -7,8 +6,6 @@ import {
76
import ErrorFormatter from './ErrorFormatter';
87

98
class ErrorHandler {
10-
errorFormatter: ErrorFormatter;
11-
129
constructor() {
1310
this.errorFormatter = new ErrorFormatter();
1411
}

packages/error-api-redux/src/errorDuck.jsx

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* @flow */
21
import { createSelector } from 'reselect';
32

43
/* Action types */
@@ -7,12 +6,12 @@ const ADD_CRASH_MESSAGE = 'ADD_CRASH_MESSAGE';
76
export const REMOVE_ERROR_MESSAGE = 'REMOVE_ERROR_MESSAGE';
87

98
/* Action creators */
10-
export const addErrorMessage = (data: any) => ({
9+
export const addErrorMessage = data => ({
1110
type: ADD_ERROR_MESSAGE,
1211
data,
1312
});
1413

15-
export const showCrashMessage = (message: string) => ({
14+
export const showCrashMessage = message => ({
1615
type: ADD_CRASH_MESSAGE,
1716
data: message,
1817
});
@@ -29,16 +28,7 @@ const initialState = {
2928
crashMessage: undefined,
3029
};
3130

32-
type ActionFlowType = {
33-
type?: string,
34-
data?: any,
35-
};
36-
type StateFlowType = {
37-
errorMessages: any,
38-
crashMessage?: string,
39-
};
40-
41-
export const errorReducer = (state: StateFlowType = initialState, action: ActionFlowType = {}) => {
31+
export const errorReducer = (state = initialState, action = {}) => {
4232
switch (action.type) {
4333
case ADD_ERROR_MESSAGE:
4434
return {

packages/error-api-redux/src/errorDuck.spec.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* @flow */
21
import { expect } from 'chai';
32

43
import {

packages/error-api-redux/src/formatters/DefaultFormatter.jsx

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
/* @flow */
21
import ErrorMessage from './ErrorMessage';
3-
import { Formatter } from './Formatter';
42

5-
type ErrorData = {
6-
feilmelding?: string,
7-
message?: string,
8-
}
9-
10-
class DefaultFormatter implements Formatter<ErrorData | string> {
3+
class DefaultFormatter {
114
isOfType = () => true
125

13-
format = (errorData: ErrorData | string) => {
6+
format = (errorData) => {
147
if (typeof errorData === 'string') {
158
return ErrorMessage.withMessage(errorData);
169
}

packages/error-api-redux/src/formatters/DefaultFormatter.spec.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* @flow */
21
import { expect } from 'chai';
32

43
import DefaultFormatter from './DefaultFormatter';

packages/error-api-redux/src/formatters/ErrorMessage.jsx

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1-
/* @flow */
21
class ErrorMessage {
3-
text: string
4-
5-
code: string
6-
7-
params: any
8-
9-
static withMessage(message: string) {
2+
static withMessage(message) {
103
const errorMessage = new ErrorMessage();
114
errorMessage.text = message;
125
return errorMessage;
136
}
147

15-
static withMessageCode(messageCode: string, params: any) {
8+
static withMessageCode(messageCode, params) {
169
const errorMessage = new ErrorMessage();
1710
errorMessage.code = messageCode;
1811
errorMessage.params = params;

packages/error-api-redux/src/formatters/Formatter.jsx

-7
This file was deleted.

packages/error-api-redux/src/formatters/RestHaltedOrDelayedFormatter.jsx

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
1-
/* @flow */
21
import { dateFormat, timeFormat } from '@fpsak-frontend/utils';
32

43
import ErrorEventType from './errorEventType';
54
import ErrorMessage from './ErrorMessage';
6-
import { Formatter } from './Formatter';
75

86
const HALTED_PROCESS_TASK_MESSAGE_CODE = 'Rest.ErrorMessage.General';
97
const DELAYED_PROCESS_TASK_MESSAGE_CODE = 'Rest.ErrorMessage.DownTime';
108

11-
type ErrorData = {
12-
message: string,
13-
status: string,
14-
eta: string,
15-
}
16-
179
// TODO (TOR) Bør kanskje ligga under rest-api
1810

19-
class RestHaltedOrDelayedFormatter implements Formatter<ErrorData> {
11+
class RestHaltedOrDelayedFormatter {
2012
type = ErrorEventType.POLLING_HALTED_OR_DELAYED;
2113

22-
isOfType = (type: string) => type === this.type;
14+
isOfType = type => type === this.type;
2315

24-
format = (errorData: ErrorData) => {
16+
format = (errorData) => {
2517
const { message, status, eta } = errorData;
2618
if (status === 'HALTED') {
2719
return ErrorMessage.withMessageCode(HALTED_PROCESS_TASK_MESSAGE_CODE, { errorDetails: message });

packages/error-api-redux/src/formatters/RestHaltedOrDelayedFormatter.spec.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* @flow */
21
import { expect } from 'chai';
32

43
import RestHaltedOrDelayedFormatter from './RestHaltedOrDelayedFormatter';

0 commit comments

Comments
 (0)