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

add advanced rules for eslint #137

Open
wants to merge 5 commits into
base: main
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
19 changes: 15 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
module.exports = {
parser: "@babel/eslint-parser",
extends: ["plugin:react/recommended", "prettier"],
extends: ["plugin:react/recommended", "plugin:jsx-a11y/recommended", "plugin:react-hooks/recommended", "prettier"],
parserOptions: {
requireConfigFile: false,
babelOptions: {
presets: ["@babel/preset-react"],
},
},
plugins: ["react", "react-hooks"],
rules: {}, // add specific rules here
ignorePatterns: ["dist", "tests", ".eslintrc.cjs"],
plugins: ["react"],
rules: {
"prefer-const": "warn",
"prefer-arrow-callback": "warn",
},
overrides: [
{
files: ["*.js", "*.jsx"], // Target all JSX files
rules: {
strict: ["error", "global"], // Apply "use strict" globally within src folder
},
},
],
ignorePatterns: ["dist", "tests", "public", ".eslintrc.cjs"],
settings: {
react: {
version: "detect",
Expand Down
94 changes: 94 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"dotenv-safe": "^8.2.0",
"enzyme": "^3.11.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.34.0",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^9.0.11",
Expand Down
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import PropTypes from "prop-types";
const App = (props) => {
useEffect(() => {
document.title = APP_TITLE;
}, [APP_TITLE]);
}, []);

return (
<IntlProvider {...props.intl}>
Expand Down
2 changes: 1 addition & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getOidcToken } from "../utils/SecurityUtils";
import { isUsingOidcAuth } from "../utils/OidcUtils";

// Axios instance for communicating with Backend
export let axiosBackend = axios.create({
export const axiosBackend = axios.create({
withCredentials: true,
});

Expand Down
2 changes: 0 additions & 2 deletions src/components/HelpIcon.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

import React from "react";
import { OverlayTrigger, Tooltip } from "react-bootstrap";
import PropTypes from "prop-types";
Expand Down
8 changes: 3 additions & 5 deletions src/components/HorizontalInput.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"use strict";

import React, { forwardRef } from "react";
import { Col, FormCheck, FormControl, FormGroup, FormLabel, FormText, InputGroup } from "react-bootstrap";
import PropTypes from "prop-types";
import Row from "react-bootstrap/Row";
import TypeaheadAnswer from "./record/TypeaheadAnswer";

const HorizontalInput = forwardRef(function HorizontalInputWithRef(props, ref) {
const HorizontalInput = (props, ref) => {
const renderInputOnType = () => {
switch (props.type) {
case "radio":
Expand Down Expand Up @@ -144,7 +142,7 @@ const HorizontalInput = forwardRef(function HorizontalInputWithRef(props, ref) {
};

return renderInputOnType();
});
};

HorizontalInput.propTypes = {
type: PropTypes.string,
Expand All @@ -169,4 +167,4 @@ HorizontalInput.defaultProps = {
inputOffset: 4,
};

export default HorizontalInput;
export default forwardRef(HorizontalInput);
8 changes: 3 additions & 5 deletions src/components/Input.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"use strict";

import React, { forwardRef } from "react";
import { FormLabel, FormGroup, FormControl, FormText, FormCheck } from "react-bootstrap";
import PropTypes from "prop-types";

const Input = forwardRef(function InputWithRef(props, ref) {
const Input = (props, ref) => {
const renderInputOnType = () => {
switch (props.type) {
case "radio":
Expand Down Expand Up @@ -80,7 +78,7 @@ const Input = forwardRef(function InputWithRef(props, ref) {
};

return renderInputOnType();
});
};

Input.propTypes = {
children: PropTypes.node.isRequired,
Expand All @@ -96,4 +94,4 @@ Input.defaultProps = {
type: "text",
};

export default Input;
export default forwardRef(Input);
2 changes: 0 additions & 2 deletions src/components/dashboard/DashboardController.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

import Dashboard from "./Dashboard";
import React from "react";
import { connect } from "react-redux";
Expand Down
2 changes: 0 additions & 2 deletions src/components/dashboard/DashboardTile.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

import React from "react";
import PropTypes from "prop-types";

Expand Down
2 changes: 1 addition & 1 deletion src/components/history/HistoryList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class HistoryList extends React.Component {
};

_handleChange = (e) => {
let change = {};
const change = {};
change[e.target.name] = e.target.value;
this.setState({ searchData: { ...this.state.searchData, ...change }, pageNumber: 1 });
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/history/HistoryRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PropTypes from "prop-types";
import { formatDateWithMilliseconds } from "../../utils/Utils";
import { useI18n } from "../../hooks/useI18n";

let HistoryRow = (props) => {
const HistoryRow = (props) => {
const { i18n } = useI18n();
const action = props.action;
const username = action.author ? action.author.username : i18n("history.non-logged");
Expand Down
2 changes: 1 addition & 1 deletion src/components/institution/Institution.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Institution extends React.Component {
}

_onChange = (e) => {
let change = {};
const change = {};
change[e.target.name] = e.target.value;
this.props.handlers.onChange(change);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/institution/InstitutionMembers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class InstitutionMembers extends React.Component {

_renderRows() {
const { institution, onEditUser, currentUser, userDeleted } = this.props;
let rows = [];
const rows = [];
const members = this.props.institutionMembers.members;
for (let i = 0, len = members.length; i < len; i++) {
const deletionLoading = !!(
Expand Down
2 changes: 1 addition & 1 deletion src/components/institution/InstitutionRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button } from "react-bootstrap";
import { LoaderSmall } from "../Loader";
import PropTypes from "prop-types";

let InstitutionRow = (props) => {
const InstitutionRow = (props) => {
const institution = props.institution;
return (
<tr>
Expand Down
4 changes: 1 addition & 3 deletions src/components/institution/InstitutionTable.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

import React from "react";
import { Table } from "react-bootstrap";

Expand Down Expand Up @@ -82,7 +80,7 @@ class InstitutionTable extends React.Component {
_renderRows() {
const { institutions, institutionDeleted } = this.props;
const onEdit = this.props.handlers.onEdit;
let rows = [];
const rows = [];
for (let i = 0, len = institutions.length; i < len; i++) {
rows.push(
<InstitutionRow
Expand Down
2 changes: 0 additions & 2 deletions src/components/institution/InstitutionsController.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

import React from "react";
import Routes from "../../constants/RoutesConstants";
import { transitionToWithOpts } from "../../utils/Routing";
Expand Down
2 changes: 0 additions & 2 deletions src/components/login/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

import React, { useEffect, useRef, useState } from "react";
import { Alert, Button, Form, Card } from "react-bootstrap";
import HorizontalInput from "../HorizontalInput";
Expand Down
4 changes: 1 addition & 3 deletions src/components/login/PasswordReset.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

import React from "react";
import { Button, Form, Card } from "react-bootstrap";
import HorizontalInput from "../HorizontalInput";
Expand Down Expand Up @@ -31,7 +29,7 @@ class PasswordReset extends React.Component {
}

onChange = (e) => {
let state = this.state;
const state = this.state;
state[e.target.name] = e.target.value;
this.setState(state);
};
Expand Down
4 changes: 1 addition & 3 deletions src/components/login/PasswordToken.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

import React from "react";
import { Alert, Button, Form, Card } from "react-bootstrap";
import HorizontalInput from "../HorizontalInput";
Expand Down Expand Up @@ -38,7 +36,7 @@ class PasswordReset extends React.Component {
}

onChange = (e) => {
let state = this.state;
const state = this.state;
state[e.target.name] = e.target.value;
this.setState(state);
};
Expand Down
2 changes: 0 additions & 2 deletions src/components/record/RecordController.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

import React from "react";
import { injectIntl } from "react-intl";
import withI18n from "../../i18n/withI18n";
Expand Down
Loading
Loading