fix flow and linter warnings

This commit is contained in:
Sebastian Sdorra
2018-08-31 10:47:42 +02:00
parent 9725f2d19f
commit d20b69ea23
13 changed files with 706 additions and 695 deletions

View File

@@ -1,29 +1,3 @@
{
"parser": "babel-eslint",
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:flowtype/recommended"
],
"plugins": [
"flowtype",
"react",
"jsx-a11y",
"import"
],
"rules": {
"quotes": ["error", "double"]
},
"env": {
"browser": true
},
"overrides": [
{
"files": [ "*.test.js" ],
"env": {
"jest": true,
"browser": true
}
}
]
"extends": "@scm-manager/eslint-config"
}

View File

@@ -42,18 +42,11 @@
"pre-commit": "jest && flow && eslint src"
},
"devDependencies": {
"@scm-manager/ui-bundler": "^0.0.7",
"babel-eslint": "^8.2.6",
"@scm-manager/ui-bundler": "^0.0.9",
"copyfiles": "^2.0.0",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"eslint": "^5.3.0",
"eslint-plugin-flowtype": "^2.50.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.10.0",
"fetch-mock": "^6.5.0",
"flow-bin": "^0.77.0",
"flow-typed": "^2.5.1",
"jest": "^23.5.0",
"node-sass-chokidar": "^1.3.0",

View File

@@ -74,6 +74,7 @@ class PluginLoader extends React.Component<Props, State> {
})
.then(script => {
// TODO is this safe???
// eslint-disable-next-line no-eval
eval(script); // NOSONAR
});
};

View File

@@ -1,3 +1,4 @@
// @flow
import React from "react";
type Props = {

View File

@@ -1,3 +1,4 @@
// @flow
import React from "react";
type Props = {

View File

@@ -1,18 +1,26 @@
// @flow
//modified from https://github.com/GA-MO/react-confirm-alert
import React from "react";
import * as React from "react";
import { render, unmountComponentAtNode } from "react-dom";
import "./ConfirmAlert.css";
type Button = {
label: string,
onClick: () => void | null
};
type Props = {
title: string,
message: string,
buttons: array
buttons: Button[]
};
class ConfirmAlert extends React.Component<Props> {
handleClickButton = button => {
if (button.onClick) button.onClick();
handleClickButton = (button: Button) => {
if (button.onClick) {
button.onClick();
}
this.close();
};
@@ -48,20 +56,26 @@ class ConfirmAlert extends React.Component<Props> {
}
}
function createElementReconfirm(properties) {
function createElementReconfirm(properties: Props) {
const divTarget = document.createElement("div");
divTarget.id = "react-confirm-alert";
document.body.appendChild(divTarget);
render(<ConfirmAlert {...properties} />, divTarget);
if (document.body) {
document.body.appendChild(divTarget);
render(<ConfirmAlert {...properties} />, divTarget);
}
}
function removeElementReconfirm() {
const target = document.getElementById("react-confirm-alert");
unmountComponentAtNode(target);
target.parentNode.removeChild(target);
if (target) {
unmountComponentAtNode(target);
if (target.parentNode) {
target.parentNode.removeChild(target);
}
}
}
export function confirmAlert(properties) {
export function confirmAlert(properties: Props) {
createElementReconfirm(properties);
}

View File

@@ -1,3 +1,4 @@
// @flow
import React from "react";
import { translate } from "react-i18next";
import { Route } from "react-router";

View File

@@ -1,3 +1,4 @@
// @flow
import React, { Component } from "react";
import Main from "./Main";
import { connect } from "react-redux";
@@ -15,6 +16,7 @@ import { PrimaryNavigation } from "../components/navigation";
import Loading from "../components/Loading";
import ErrorPage from "../components/ErrorPage";
import { Footer, Header } from "../components/layout";
import type { Me } from "../types/Me";
type Props = {
me: Me,

View File

@@ -1,5 +1,5 @@
//@flow
import React from 'react';
import React from "react";
import NavLink from "../../../components/navigation/NavLink";
import { translate } from "react-i18next";
import type { Group } from "../../types/Group";

View File

@@ -217,7 +217,7 @@ describe("groups fetch()", () => {
const callMe = () => {
called = true;
}
};
const store = mockStore({});
return store.dispatch(createGroup(humanGroup, callMe)).then(() => {
const actions = store.getActions();
@@ -254,9 +254,9 @@ describe("groups fetch()", () => {
const actions = store.getActions();
expect(actions[0].type).toEqual(MODIFY_GROUP_PENDING);
expect(actions[1].type).toEqual(MODIFY_GROUP_SUCCESS);
expect(actions[1].payload).toEqual(humanGroup)
expect(actions[1].payload).toEqual(humanGroup);
});
})
});
it("should call the callback after modifying group", () => {
fetchMock.putOnce("http://localhost:8081/api/rest/v2/groups/humanGroup", {
@@ -266,7 +266,7 @@ describe("groups fetch()", () => {
let called = false;
const callback = () => {
called = true;
}
};
const store = mockStore({});
return store.dispatch(modifyGroup(humanGroup, callback)).then(() => {
@@ -275,7 +275,7 @@ describe("groups fetch()", () => {
expect(actions[1].type).toEqual(MODIFY_GROUP_SUCCESS);
expect(called).toBe(true);
});
})
});
it("should fail modifying group on HTTP 500", () => {
fetchMock.putOnce("http://localhost:8081/api/rest/v2/groups/humanGroup", {
@@ -290,7 +290,7 @@ describe("groups fetch()", () => {
expect(actions[1].type).toEqual(MODIFY_GROUP_FAILURE);
expect(actions[1].payload).toBeDefined();
});
})
});
it("should delete successfully group humanGroup", () => {
fetchMock.deleteOnce("http://localhost:8081/api/rest/v2/groups/humanGroup", {
@@ -493,7 +493,7 @@ describe("selector tests", () => {
});
it("should return null when there are no groups in the state", () => {
expect(getGroupsFromState({})).toBe(null)
expect(getGroupsFromState({})).toBe(null);
});
it("should return true, when fetch groups is pending", () => {
@@ -563,23 +563,23 @@ describe("selector tests", () => {
expect(isCreateGroupPending({pending: {
[CREATE_GROUP]: true
}})).toBeTruthy();
})
});
it("should return false if create group is not pending", () => {
expect(isCreateGroupPending({})).toBe(false);
})
});
it("should return error if creating group failed", () => {
expect(getCreateGroupFailure({
failure: {
[CREATE_GROUP]: error
}
})).toEqual(error)
})
})).toEqual(error);
});
it("should return undefined if creating group did not fail", () => {
expect(getCreateGroupFailure({})).toBeUndefined()
})
expect(getCreateGroupFailure({})).toBeUndefined();
});
it("should return true, when delete group humanGroup is pending", () => {
@@ -613,20 +613,20 @@ describe("selector tests", () => {
pending: {
[CREATE_GROUP]: true
}
}
};
expect(isCreateGroupPending(state)).toBe(true);
})
});
it("should return false, if createGroup is not pending", () => {
expect(isCreateGroupPending({})).toBe(false)
})
expect(isCreateGroupPending({})).toBe(false);
});
it("should return error of createGroup failed", () => {
const state = {
failure: {
[CREATE_GROUP]: error
}
}
expect(getCreateGroupFailure(state)).toEqual(error)
})
};
expect(getCreateGroupFailure(state)).toEqual(error);
});
});

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-console */
// In production, we register a service worker to serve assets from local cache.
// This lets the app load faster on subsequent visits in production, and gives
@@ -9,9 +10,9 @@
// This link also includes instructions on opting out of this behavior.
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
window.location.hostname === "localhost" ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
window.location.hostname === "[::1]" ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
@@ -19,7 +20,7 @@ const isLocalhost = Boolean(
);
export default function register() {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
if (publicUrl.origin !== window.location.origin) {
@@ -29,7 +30,7 @@ export default function register() {
return;
}
window.addEventListener('load', () => {
window.addEventListener("load", () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
@@ -40,8 +41,8 @@ export default function register() {
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://goo.gl/SC7cgQ'
"This web app is being served cache-first by a service " +
"worker. To learn more, visit https://goo.gl/SC7cgQ"
);
});
} else {
@@ -59,25 +60,25 @@ function registerValidSW(swUrl) {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (installingWorker.state === "installed") {
if (navigator.serviceWorker.controller) {
// At this point, the old content will have been purged and
// the fresh content will have been added to the cache.
// It's the perfect time to display a "New content is
// available; please refresh." message in your web app.
console.log('New content is available; please refresh.');
console.log("New content is available; please refresh.");
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
console.log("Content is cached for offline use.");
}
}
};
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
console.error("Error during service worker registration:", error);
});
}
@@ -88,7 +89,7 @@ function checkValidServiceWorker(swUrl) {
// Ensure service worker exists, and that we really are getting a JS file.
if (
response.status === 404 ||
response.headers.get('content-type').indexOf('javascript') === -1
response.headers.get("content-type").indexOf("javascript") === -1
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
@@ -103,15 +104,17 @@ function checkValidServiceWorker(swUrl) {
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
"No internet connection found. App is running in offline mode."
);
});
}
export function unregister() {
if ('serviceWorker' in navigator) {
if ("serviceWorker" in navigator) {
navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});
}
}
/* eslint-enable no-console */

View File

@@ -6,7 +6,6 @@ import type { Repository } from "../../types/Repositories";
import DateFromNow from "../../../components/DateFromNow";
import RepositoryEntryLink from "./RepositoryEntryLink";
import classNames from "classnames";
import { ExtensionPoint } from "@scm-manager/ui-extensions";
import RepositoryAvatar from "./RepositoryAvatar";
const styles = {

File diff suppressed because it is too large Load Diff