Skip to content

Commit

Permalink
Merge pull request #303 from unigraph-dev/chore/lint-code-style
Browse files Browse the repository at this point in the history
Chore/lint code style
  • Loading branch information
thesophiaxu committed Dec 28, 2021
2 parents 99d2e20 + 4595b95 commit a82ac19
Show file tree
Hide file tree
Showing 135 changed files with 10,633 additions and 7,564 deletions.
64 changes: 52 additions & 12 deletions .eslintrc.js
Expand Up @@ -2,19 +2,59 @@ module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'react-app',
'plugin:@typescript-eslint/recommended',
'airbnb', 'airbnb/hooks',
'eslint:recommended',
'react-app',
'plugin:@typescript-eslint/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
],
ignorePatterns: [
"**/lib/**/*.*",
"**/dist/**/*.*",
"**/build/**/*.*",
"**/vendor/**/*.*",
"**/*.test.ts",
"**/*.config.js"
]
};
'**/lib/**/*.*',
'**/dist/**/*.*',
'**/build/**/*.*',
'**/vendor/**/*.*',
'**/*.test.ts',
'**/*.config.js',
],
rules: {
indent: ['error', 4, { ignoredNodes: ['JSXElement *', 'JSXElement'] }],
'react/jsx-indent': ['error', 4],
'react/jsx-indent-props': ['error', 4],
'max-len': [
'error', {
code: 120,
tabWidth: 4,
ignoreComments: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
},
],
'import/prefer-default-export': 'off', // do not prefer default export
'import/no-extraneous-dependencies': 'off', // using monorepo
'no-underscore-dangle': 'off', // unigraph data model
'import/extensions': [ // targeting es module support so file extension is not needed
'error',
'ignorePackages',
{
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
},
],
'react/jsx-filename-extension': ['error', { extensions: ['.tsx', '.jsx'] }],
'react/jsx-props-no-spreading': 'off',
'react/function-component-definition': 'off',
'react/prop-types': 'off', // for now, maybe we'll enforce this later
'no-param-reassign': 'warn', // also, for now
'import/no-unresolved': 'off', // temporarily disable unresolved check
'react/react-in-jsx-scope': 'off', // unnecessary for new jsx transpilation
'jsx-a11y/no-static-element-interactions': 'off', // disable for now
'jsx-a11y/click-events-have-key-events': 'off', // disable for now
},
};
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Expand Up @@ -15,7 +15,7 @@ jobs:

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

- name: Cache node modules
uses: actions/cache@v2
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:

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

- name: Cache node modules
uses: actions/cache@v2
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:

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

- run: yarn install

Expand Down
23 changes: 12 additions & 11 deletions package.json
Expand Up @@ -24,24 +24,25 @@
"electron-start": "yarn workspace unigraph-dev-electron start"
},
"engines": {
"node": "^15.14.0",
"npm": "^7.7.6"
"node": ">=16.0.0",
"npm": "^8.1.2"
},
"devDependencies": {
"@babel/eslint-parser": "^7.13.4",
"@types/jest": "^26.0.20",
"@types/json-stable-stringify": "^1.0.32",
"@types/testing-library__dom": "^7.5.0",
"@typescript-eslint/eslint-plugin": "^4.15.2",
"@typescript-eslint/parser": "^4.15.2",
"@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/parser": "^5.8.1",
"babel-eslint": "^10.1.0",
"eslint": "^7.20.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.3.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint": "^8.2.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-react-app": "^7.0.0",
"eslint-plugin-flowtype": "^8.0.3",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"jest": "^26.6.3",
"ts-jest": "^26.5.2",
"typescript": "^4.2.2"
Expand Down
4 changes: 2 additions & 2 deletions packages/unigraph-dev-backend/package.json
Expand Up @@ -4,8 +4,8 @@
"description": "",
"main": "dist/index.js",
"engines": {
"node": "^15.14.0",
"npm": "^7.7.6"
"node": ">=16.0.0",
"npm": "^8.1.2"
},
"scripts": {
"build": "tsc && (cp ../../secrets.env.json dist || true)",
Expand Down
8 changes: 4 additions & 4 deletions packages/unigraph-dev-backend/src/asyncManager.ts
Expand Up @@ -5,15 +5,15 @@
import AsyncLock from 'async-lock';

export const resources = [
"caches/schema",
'caches/schema',
];

export function getAsyncLock () { return new AsyncLock() }
export function getAsyncLock() { return new AsyncLock(); }

export function withLock(lock: AsyncLock, key: string | string[], it: () => Promise<any>): Promise<any> {
return lock.acquire(key, (done) => {
const fn = it();
fn.then((res) => done(undefined, res))
.catch((e) => done(e, undefined))
.catch((e) => done(e, undefined));
});
}
}
4 changes: 2 additions & 2 deletions packages/unigraph-dev-backend/src/caches.ts
@@ -1,12 +1,12 @@
// Abstract definition for caches

import DgraphClient from "./dgraphClient";
import DgraphClient from './dgraphClient';

export type Cache<T> = {
data: T,
dataAlt?: T[],
updateNow(): any,
cacheType: "subscription" | "manual",
cacheType: 'subscription' | 'manual',
/* eslint-disable */ // TODO: Temporarily appease the linter, remember to fix it later
subscribe(listener: Function): any
}
76 changes: 47 additions & 29 deletions packages/unigraph-dev-backend/src/custom.d.ts
@@ -1,6 +1,6 @@
import DgraphClient from './dgraphClient';
import { PackageDeclaration } from 'unigraph-dev-common/lib/types/packages';
import { Query, UnigraphNotification } from 'unigraph-dev-common/lib/types/unigraph';
import DgraphClient from './dgraphClient';

declare global {
namespace Express {
Expand All @@ -16,70 +16,88 @@ declare type UnigraphUpsert = {
appends: any[]
}

declare type Subscription = {
data: any,
query: Query, // something like () { uid }
subType: 'polling' | 'pushing',
callbackType: 'function' | 'messageid',
id: number | string, // must be provided, regardless of using function or messageid
/* eslint-disable */ // TODO: Temporarily appease the linter, remember to fix it later
function?: Function,
msgPort?: IWebsocket,
regTime: number, // time of registration, can be used to manually terminate subscription going too long
connId?: string,
clientId?: string,
hibernated?: boolean,
queryNow?: any,
finalQuery?: any,
queryTime?: number,
};

declare type EventCreateUnigraphSchema = {
"type": "event",
"event": "create_unigraph_schema",
'type': 'event',
'event': 'create_unigraph_schema',
schema: Record<string, unknown> | Record<string, unknown>[],
id: number
}

declare type EventAddUnigraphPackage = {
"type": "event",
"event": "add_unigraph_package",
'type': 'event',
'event': 'add_unigraph_package',
id: number,
package: PackageDeclaration,
update: boolean
}

declare type EventCreateUnigraphObject = {
"type": "event",
"event": "create_unigraph_object",
'type': 'event',
'event': 'create_unigraph_object',
object: Record<string, unknown>,
id: number,
schema: string | undefined,
padding: boolean | undefined
}

declare type EventUpdateSPO = {
type: "event",
event: "update_spo",
type: 'event',
event: 'update_spo',
objects: string[]
id: number
}

declare type EventDeleteUnigraphObject = {
type: "event",
event: "delete_unigraph_object",
type: 'event',
event: 'delete_unigraph_object',
id: number,
uid: string,
permanent?: boolean
}

declare type EventCreateDataByJson = {
type: "event",
event: "create_data_by_json",
type: 'event',
event: 'create_data_by_json',
id: number,
data: Record<string, unknown>
}

declare type EventSetDgraphSchema = {
type: "event",
event: "set_dgraph_schema",
type: 'event',
event: 'set_dgraph_schema',
id: number,
schema: string
}

declare type EventQueryByStringWithVars = {
type: "event",
event: "query_by_string_with_vars",
type: 'event',
event: 'query_by_string_with_vars',
vars: Record<string, unknown>,
query: string,
id: number
}

declare type EventSubscribeObject = {
type: "event",
event: "subscribe_to_object",
type: 'event',
event: 'subscribe_to_object',
id: number | string,
uid: string,
connId: string,
Expand All @@ -90,33 +108,33 @@ declare type EventSubscribeObject = {
}

declare type EventSubscribeQuery = {
type: "event",
event: "subscribe_to_query",
type: 'event',
event: 'subscribe_to_query',
id: number | string,
queryFragment: string,
connId: string,
options?: { noExpand?: boolean },
}

declare type EventSubscribe = {
type: "event",
event: "subscribe",
type: 'event',
event: 'subscribe',
id: number | string,
query: Query,
connId: string,
update?: boolean,
}

declare type EventGetQueries = {
type: "event",
event: "get_queries",
type: 'event',
event: 'get_queries',
id: number | string
fragments: any[]
}

declare type EventSubscribeType = {
type: "event",
event: "subscribe_to_type",
type: 'event',
event: 'subscribe_to_type',
id: number | string,
schema: string,
connId: string,
Expand All @@ -128,8 +146,8 @@ declare type EventSubscribeType = {
}

declare type EventUnsubscribeById = {
type: "event",
event: "unsubscribe_by_id",
type: 'event',
event: 'unsubscribe_by_id',
id: number | string
}

Expand Down

0 comments on commit a82ac19

Please sign in to comment.