Skip to content

Commit

Permalink
Merge pull request #73 from devuxd/newMain
Browse files Browse the repository at this point in the history
Refactoring the code to match the styles enforced by Lint
  • Loading branch information
SaharMehrpour authored Jun 27, 2024
2 parents 57d0f1f + 738c2d4 commit 60435b5
Show file tree
Hide file tree
Showing 48 changed files with 3,995 additions and 3,566 deletions.
9 changes: 9 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build/
node_modules/
config-overrides.js
src/configureMonaco.js
src/monaco-worker-loader-proxy.dev.js
src/monaco-worker-loader-proxy.js
src/registerServiceWorker.js
src/core/generated-parser/
src/web-socket-js/
71 changes: 71 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"env": {
"browser": true,
"node": true,
"jasmine": true,
"es6": true
},
"extends": [
"eslint:recommended",
"google",
"plugin:import/errors",
"plugin:jsx-a11y/recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended"
],
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 2021,
"sourceType": "module",
"babelOptions": {
"presets": ["@babel/preset-react"]
}
},
"plugins": [
"react",
"import",
"jsx-a11y"
],
"rules": {
"camelcase": "off",
"guard-for-in": "warn",
"import/default": "off",
"import/export": "off",
"import/namespace": "off",
"indent": ["error", 4, {"SwitchCase": 1}],
"jsx-a11y/click-events-have-key-events": "off",
"jsx-a11y/no-noninteractive-element-interactions": "off",
"jsx-a11y/no-static-element-interactions": "off",
"max-len": "off",
"new-cap": "off",
"no-case-declarations": "off",
"no-constant-condition": "off",
"no-control-regex": "off",
"no-invalid-this": "off",
"no-prototype-builtins": "off",
"no-unused-vars": ["error", {"varsIgnorePattern": "React", "argsIgnorePattern": "^_"}],
"object-curly-spacing": ["error", "never"],
"prefer-promise-reject-errors": "off",
"quotes": ["error", "double"],
"react/prop-types": "off",
"react/no-unescaped-entities": "off",
"require-jsdoc": "off",
"valid-jsdoc": "off"
},
"overrides": [
{
"files": ["*Constants.js", "*Constant.js", "*Config.js"],
"rules": {"camelcase": "off"}
},
{
"files": ["*.test.js", "src/ui/RulePad/rulePad.js"],
"rules": {"max-len": "off"}
}
],
"settings": {
"react": {
"version": "detect"
}
}
}
26 changes: 26 additions & 0 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ESLint

on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'

jobs:
eslint:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: '18'

- name: Install ESLint
run: npm install [email protected] @microsoft/[email protected]

- name: Run ESLint
run: npx eslint . --ext .js --config .eslintrc.json
12 changes: 12 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@babel/env",
{
"targets": {
"node": "12"
}
}
]
]
}
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@
"wink-pos-tagger": "1.5.0"
},
"devDependencies": {
"@babel/eslint-parser": "^7.24.7",
"@babel/plugin-proposal-private-property-in-object": "7.21.11",
"@eslint/js": "9.5.0",
"eslint": "^7.32.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jsx-a11y": "6.9.0",
"eslint-plugin-react": "7.34.3",
"eslint-plugin-react-hooks": "4.6.2",
"gh-pages": "3.1.0",
"globals": "15.6.0",
"jasmine": "5.1.0",
"react-app-rewired": "2.1.8",
"react-scripts": "4.0.3"
},
Expand Down
55 changes: 28 additions & 27 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import MinedRulesComponent from "./ui/MiningRules/minedRulesComponent";
import {hashConst} from "./ui/uiConstants";

class App extends Component {

constructor(props) {
super(props);
/**
Expand All @@ -30,18 +29,17 @@ class App extends Component {
}

if ("onhashchange" in window) { // event supported?
window.onhashchange = function () {
let hash = window.location.hash.split("/");
window.onhashchange = function() {
const hash = window.location.hash.split("/");
hash.splice(0, 1); // remove #
props.onHashChange(hash);
}
}
else { // event not supported:
};
} else { // event not supported:
let storedHash = window.location.hash;
window.setInterval(function () {
window.setInterval(function() {
if (window.location.hash !== storedHash) {
storedHash = window.location.hash;
let hash = storedHash.split("/");
const hash = storedHash.split("/");
hash.splice(0, 1); // remove #
props.onHashChange(hash);
}
Expand All @@ -50,7 +48,7 @@ class App extends Component {

window.location.hash = "#/index";

this.state = {loadingGif: false}
this.state = {loadingGif: false};
}

render() {
Expand All @@ -66,38 +64,42 @@ class App extends Component {
<HeaderBar/>
</div>
<div id={"tableOfContent"}
className={
([hashConst.index, hashConst.tagJsonChanged, hashConst.ruleJsonChanged].indexOf(this.props.currentHash[0]) === -1 ) ? "main container hidden" : "main container"
}>
className={
([hashConst.index, hashConst.tagJsonChanged, hashConst.ruleJsonChanged]
.indexOf(this.props.currentHash[0]) === -1 ) ? "main container hidden" : "main container"
}>
<TableOfContents/>
</div>
<div id={"ruleResults"}
className={
([hashConst.rules, hashConst.tag, hashConst.codeChanged, hashConst.rulesForFile, hashConst.violatedRules].indexOf(this.props.currentHash[0]) === -1 ) ? "main container hidden" : "main container"
}>
className={
([hashConst.rules, hashConst.tag, hashConst.codeChanged, hashConst.rulesForFile, hashConst.violatedRules]
.indexOf(this.props.currentHash[0]) === -1 ) ? "main container hidden" : "main container"
}>
<RuleTable/>
</div>
<div id={"learnDesignRules"}
className={
([hashConst.learnDesignRules].indexOf(this.props.currentHash[0]) === -1 ) ? "main container hidden" : "main container"
}>
className={
([hashConst.learnDesignRules].indexOf(this.props.currentHash[0]) === -1 ) ?
"main container hidden" : "main container"
}>
<MinedRulesComponent/>
</div>
<div style={{width: "100%", height: "100px"}}/>
</div>
</div>
)
);
}

static getDerivedStateFromProps(props, state) {
if (props.loadingGif !== state.loadingGif)
if (props.loadingGif !== state.loadingGif) {
return {loadingGif: props.loadingGif};
}
return null;
}

renderLoading() {
return (<div id={"loadingGif"}
className={(this.state.loadingGif ? "" : "hidden")}>
className={(this.state.loadingGif ? "" : "hidden")}>
<div className={"overlayLoading"}>
<div className={"spinnerContainer"}>
<div className={"loadingTitle"}>
Expand All @@ -108,23 +110,22 @@ class App extends Component {
</div>
</div>);
}

}

// map state to props
function mapStateToProps(state) {
return {
currentHash: state.currentHash,
loadingGif: state.loadingGif
}
loadingGif: state.loadingGif,
};
}

function mapDispatchToProps(dispatch) {
return {
onHashChange: (hash) => {
dispatch(hashChange(hash));
}
}
},
};
}

export default connect(mapStateToProps, mapDispatchToProps)(App);
export default connect(mapStateToProps, mapDispatchToProps)(App);
12 changes: 6 additions & 6 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
it("renders without crashing", () => {
const div = document.createElement("div");
ReactDOM.render(<App />, div);
});
Loading

0 comments on commit 60435b5

Please sign in to comment.