Skip to content

Commit

Permalink
fix: TECH-398 moves eslint-config-dhis2 to the capture app and fixes …
Browse files Browse the repository at this point in the history
…eslint errors (#798)

* chore: eslints

* chore: adds airbnb

* chore: eslint reports correctly

* chore: downgrades version of airbnb so that it matches dhis2 package

* chore: adds browser

* chore: fixes all errors

* fix: errors after merge of master

* chore: disables lines so that build goes through

* chore:  adds eslint-disable-next-line jsx-a11y/anchor-has-content

* chore: fixes eslint warning

* chore: rebase

* chore: fixes all eslint errors from rebase

* chore: semi

* chore: eslint

* chore: suppress
  • Loading branch information
paschalidi authored Jul 2, 2020
1 parent e1493b4 commit 500eca3
Show file tree
Hide file tree
Showing 191 changed files with 3,312 additions and 1,541 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
*.json
src/locales/index.js
39 changes: 34 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,58 @@
}
},
"extends": [
"dhis2",
"airbnb",
"plugin:flowtype/recommended"
],
"plugins": [
"flowtype"
],
"env": {
"jest": true
"browser": true,
"jest": true,
},
"globals": {
"cy": true,
"document": true,
"window": true,
"it": true,
"expect": true,
"appPackage": true
},
"rules": {
"indent": [2, 4],
"max-len": [
1, 120, 4, {
"ignoreComments": true,
"ignoreUrls": true,
"ignorePattern": "^\\s*var\\s.+=\\s*require\\s*\\("
}
],
"complexity": [1, 5],
"no-prototype-builtins": "off",
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "always-multiline"
}],
"no-multi-spaces": ["error", {"ignoreEOLComments": true}],
"no-return-assign": ["error", "except-parens"],
"react/jsx-indent": [2, 4],
"react/jsx-indent-props": [2, 4],
"react/prefer-es6-class": [1, "always"],
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react/no-unused-prop-types": [2, { "skipShapeProps": true }],
"react/forbid-prop-types": [0],
"no-param-reassign": 0,
"react/prop-types": 0,
"import/prefer-default-export": 0,
"react/prefer-stateless-function": 0,
"no-unused-expressions": 0,
"no-unused-vars": [
"warn",
"error",
{
"vars": "all",
"args": "after-used",
Expand All @@ -43,7 +71,7 @@
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": false,
"devDependencies": ["**/*.test.js"],
"optionalDependencies": false,
"peerDependencies": true
}
Expand Down Expand Up @@ -85,7 +113,8 @@
]
},
"settings": {
"import/resolver": {
"import/resolver": {
"node": { "extensions": [".js", ".mjs"] },
"webpack": {
"config": "config/eslint/webpack.config.js"
}
Expand Down
2 changes: 1 addition & 1 deletion cypress-cucumber-preprocessor.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
nonGlobalStepDefinitions: true,
}
};
1 change: 1 addition & 0 deletions cypress/integration/test/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { Given } from 'cypress-cucumber-preprocessor/steps';

Given('opens', () => {
Expand Down
6 changes: 3 additions & 3 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const plugins = require('@dhis2/cli-utils-cypress/plugins')
const plugins = require('@dhis2/cli-utils-cypress/plugins');

module.exports = (on, config) => {
plugins(on, config)
plugins(on, config);

// Add additional plugins here
}
};
2 changes: 1 addition & 1 deletion cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import '@dhis2/cli-utils-cypress/support'
import '@dhis2/cli-utils-cypress/support';

// Add additional support functions here
6 changes: 3 additions & 3 deletions flow/dateFn.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable */
declare module "date-fns/locale/nb" {
// @flow
declare module 'date-fns/locale/nb' {
declare module.exports: any;
}
}
6 changes: 3 additions & 3 deletions flow/infiniteCalendar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable */
declare module "react-infinite-calendar/styles.css" {
// @flow
declare module 'react-infinite-calendar/styles.css' {
declare module.exports: any;
}
}
6 changes: 3 additions & 3 deletions flow/momentExtensions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable */
declare module "moment/locale/nb" {
// @flow
declare module 'moment/locale/nb' {
declare module.exports: any;
}
}
19 changes: 16 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"private": false,
"dependencies": {
"@dhis2/app-runtime": "^2.2.2",
"@dhis2/cli-utils-cypress": "^2.2.1",
"@dhis2/d2-i18n": "^1.0.6",
"@dhis2/d2-icons": "^1.0.1",
"@dhis2/d2-ui-app": "^2.0.0",
Expand Down Expand Up @@ -61,6 +62,10 @@
"typeface-roboto": "^0.0.54",
"uuid": "^3.3.2"
},
"_comment": "resolutions should be reoved after the https://github.com/babel/babel-eslint/issues/681 is resolved.",
"resolutions": {
"@babel/parser": "7.7.5"
},
"scripts": {
"manualBuild": "node verifyCacheVersion.js && yarn localize && d2-manifest package.json ./public/manifest.webapp && REACT_APP_DHIS2_BASE_URL='../../..' react-scripts build && mkdirp buildzip/ && pushd build && bestzip ../buildzip/NewCaptureApp.zip * && popd",
"start": "react-scripts start",
Expand All @@ -73,7 +78,7 @@
"localize": "yarn extract-pot && d2-i18n-generate -n default -p ./i18n/ -o ./src/locales/",
"prestart": "node verifyCacheVersion.js && yarn localize && d2-manifest package.json ./public/manifest.webapp",
"docs": "NODE_ENV=development jsdoc -c jsdoc-conf.json",
"linter:check": "eslint -c .eslintrc src/**",
"linter:check": "eslint -c .eslintrc . --quiet",
"cypress:start": "BROWSER=none REACT_APP_DHIS2_BASE_URL=https://play.dhis2.org/dev yarn start",
"cy:open": "d2-utils-cypress open --appStart 'yarn cypress:start'",
"cy:run": "d2-utils-cypress run --appStart 'yarn cypress:start'"
Expand All @@ -90,8 +95,16 @@
"docdash": "^1.2.0",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"eslint-config-dhis2": "^3.0.7",
"eslint": "6.8.0",
"eslint-config-airbnb": "^15.1.0",
"eslint-friendly-formatter": "^3.0.0",
"eslint-import-resolver-webpack": "^0.12.1",
"eslint-plugin-flowtype": "^5.1.3",
"eslint-plugin-import": "2.7.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "2.5.0",
"fake-indexeddb": "^2.1.1",
"flow-bin": "^0.125.1",
"husky": "^4.2.5",
Expand All @@ -100,7 +113,7 @@
"jsdoc-babel": "^0.5.0",
"jsdoc-export-default-interop": "^0.3.1",
"mkdirp": "^0.5.1",
"redux-devtools-extension": "^2.13.8"
"redux-devtools-extension": "^2.13.2"
},
"manifest.webapp": {
"version": "1.0.5",
Expand Down
5 changes: 2 additions & 3 deletions src/components/App/AppContents.component.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// @flow
import React, { Component } from 'react';
import { Route, Switch } from 'react-router'; //eslint-disable-line
// import HeaderBar from '@dhis2/d2-ui-header-bar';
import { Route, Switch } from 'react-router';
import { HeaderBar } from '@dhis2/ui-widgets';
import { withStyles } from '@material-ui/core/styles';
import NetworkStatusBadge from 'capture-core/components/NetworkStatusBadge/NetworkStatusBadge.component';

import { NewEventPage } from 'capture-core/components/Pages/NewEvent';
import { ViewEventPage } from 'capture-core/components/Pages/ViewEvent';
import { NewEnrollmentPage } from 'capture-core/components/Pages/NewEnrollment';
import { SearchPage } from '../../core_modules/capture-core/components/Pages/Search';
import { MainPage } from 'capture-core/components/Pages/MainPage';
import { SearchPage } from 'capture-core/components/Pages/Search';


const styles = theme => ({
Expand Down
29 changes: 1 addition & 28 deletions src/core_modules/capture-core-utils/parsers/date.parser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @flow
/* eslint-disable complexity */
import moment from 'capture-core-utils/moment/momentResolver';

const getReturnObject = (momentDate: ?moment$Moment) => ({
Expand Down Expand Up @@ -67,33 +66,7 @@ function parseWithSeparator(dateString: string, localeFormat: string, separatorP
return parseData;
}

function manipulateDayOrMonthInFormat(format: string, key: string) { // eslint-disable-line
const stringPattern = `${key}+`;
const matchPattern = new RegExp(stringPattern);
const partMatches = format.match(matchPattern);
const part = partMatches && partMatches[0];

let manipulatedFormat = format;
if (part) {
let newPart;
switch (part.length) {
case 1:
newPart = key + key;
break;
case 2:
newPart = key;
break;
default:
break;
}
if (newPart) {
manipulatedFormat = format.replace(part, newPart);
}
}
return manipulatedFormat;
}

function manipulateFormatAndParseWithoutSeparator(dateString: string, localeFormat: string) { // eslint-disable-line
function manipulateFormatAndParseWithoutSeparator() {
// rejecting this for now, didn't work as expected. Need to look into it more.
return getReturnObject(null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable class-methods-use-this */
/* eslint-disable no-underscore-dangle */
import { errorCreator } from '../errorCreator';

class Indexer {
Expand Down Expand Up @@ -103,6 +101,7 @@ class DomLocalStorageAdapter {
}),
)
.then(() => {
// eslint-disable-next-line no-underscore-dangle
this._executeDestroy();
DomLocalStorageAdapter.storage.setItem(versionKey, JSON.stringify(this.version));
return Promise.resolve();
Expand Down Expand Up @@ -130,6 +129,7 @@ class DomLocalStorageAdapter {
set(store, dataObject) {
return new Promise((resolve, reject) => {
try {
// eslint-disable-next-line no-underscore-dangle
this._executeSet(store, dataObject);
resolve();
} catch (error) {
Expand All @@ -141,6 +141,7 @@ class DomLocalStorageAdapter {
setAll(store, dataArray) {
try {
dataArray.forEach((dataObject) => {
// eslint-disable-next-line no-underscore-dangle
this._executeSet(store, dataObject);
});
return Promise.resolve();
Expand Down Expand Up @@ -190,6 +191,7 @@ class DomLocalStorageAdapter {
}

getKeys(store) {
// eslint-disable-next-line no-underscore-dangle
return Promise.resolve(this._executeGetKeys(store));
}

Expand All @@ -200,18 +202,22 @@ class DomLocalStorageAdapter {
}

remove(store, key) {
// eslint-disable-next-line no-underscore-dangle
this._executeRemove(store, key);
return Promise.resolve();
}

_executeRemoveAll(store) {
// eslint-disable-next-line no-underscore-dangle
const keys = this._executeGetKeys(store);
keys.forEach((key) => {
// eslint-disable-next-line no-underscore-dangle
this._executeRemove(store, key);
});
}

removeAll(store) {
// eslint-disable-next-line no-underscore-dangle
return Promise.resolve(this._executeRemoveAll(store));
}

Expand All @@ -236,12 +242,14 @@ class DomLocalStorageAdapter {

_executeDestroy() {
this.objectStoreNames.forEach((store) => {
// eslint-disable-next-line no-underscore-dangle
this._executeRemoveAll(store);
this.indexer[store].destroy();
});
}
destroy() {
this.opened = false;
// eslint-disable-next-line no-underscore-dangle
this._executeDestroy();
return Promise.resolve();
}
Expand Down
10 changes: 6 additions & 4 deletions src/core_modules/capture-core-utils/storage/IndexedDBAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable complexity */
/* eslint-disable no-underscore-dangle */
import isDefined from 'd2-utilizr/lib/isDefined';
import log from 'loglevel';
import { errorCreator } from '../errorCreator';
Expand Down Expand Up @@ -256,6 +254,7 @@ class IndexedDBAdapter {
}),
)
.then(() => {
// eslint-disable-next-line no-underscore-dangle
this._upgrade(onCreateObjectStore);
return Promise.resolve();
})
Expand Down Expand Up @@ -408,13 +407,13 @@ class IndexedDBAdapter {
onIDBGetRequest(objectStore, IndexedDBAdapter) :
objectStore.getAll(keyRange, batchSize);

request.onsuccess = (e) => {
request.onsuccess = () => {
const values = request.result;
const count = values ? values.length : 0;
let lastId;
if (count > 0) {
values.forEach((value) => {
// value[this.keyPath] = cursor.primaryKey || cursor.key;
// eslint-disable-next-line no-underscore-dangle
this._processGetAllItem(value, predicate, project, records);
});
lastId = values[count - 1].id;
Expand Down Expand Up @@ -451,6 +450,7 @@ class IndexedDBAdapter {
if (cursor) {
cursor.value[this.keyPath] = cursor.primaryKey || cursor.key;
const dbValue = cursor.value;
// eslint-disable-next-line no-underscore-dangle
this._processGetAllItem(dbValue, predicate, project, records);
cursor.continue();
}
Expand Down Expand Up @@ -481,7 +481,9 @@ class IndexedDBAdapter {
tx = this.db.transaction([store], IndexedDBAdapter.transactionMode.READ_ONLY);
const objectStore = tx.objectStore(store);
batchSize ?
// eslint-disable-next-line no-underscore-dangle
this._getAllInBatches(objectStore, options, records, abortTx) :
// eslint-disable-next-line no-underscore-dangle
this._getAllWithCursor(objectStore, options, records, abortTx);

tx.oncomplete = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ it('upgrade Local Storage and retain some data', async () => {
version: 2,
});
let tempValue;
await idbAdapterVersion2.open((adapter) => {
return adapter.get(storeName, '1').then((v) => { tempValue = v; });
},
(adapter) => {
return adapter.set(storeName, tempValue);
});
await idbAdapterVersion2.open(adapter => adapter.get(storeName, '1').then((v) => { tempValue = v; }),
adapter => adapter.set(storeName, tempValue));
const valueAfterUpgrade = await idbAdapterVersion2.get(storeName, '1');
expect(valueAfterUpgrade.value.prop1).toEqual('prop1value');
});
Expand Down
Loading

0 comments on commit 500eca3

Please sign in to comment.