Skip to content

Commit

Permalink
feat: add rule require-await (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
LancelotLewis authored Jun 6, 2023
1 parent a893b13 commit 21a9977
Show file tree
Hide file tree
Showing 31 changed files with 2,521 additions and 2,133 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Lint

env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true

on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
Publish:
runs-on: ubuntu-latest

if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"

steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: pnpm/action-setup@v2
with:
version: latest
- uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'pnpm'
- run: pnpm i --no-frozen-lockfile

- name: Lint
run: pnpm lint
11 changes: 5 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@ jobs:

steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: main
fetch-depth: 0
token: ${{ secrets.GIT_HUB_TOKEN }}
- uses: pnpm/action-setup@v2.0.1
- uses: pnpm/action-setup@v2
with:
version: latest
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: '14'
node-version: '16'
cache: 'pnpm'
- run: npm add -g @antfu/ni
- run: nci
- run: pnpm i --no-frozen-lockfile

- name: Config Git
run: |
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.2.4 (June 06, 2023)

- chore: add lint in ci
- chore: fix lint error in example
- feat: add rule `require-await`

## 0.2.3 (August 22, 2022)

- feat: disable test.skip and test.only
Expand Down
18 changes: 9 additions & 9 deletions examples/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
"test": "jest"
},
"dependencies": {
"react": "^18.0.0",
"react-dom": "^18.0.0"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@arcblock/eslint-config": "workspace:*",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@vitejs/plugin-react": "^1.3.0",
"eslint": "8.16.0",
"jest": "^28.1.0",
"prettier": "^2.6.2",
"vite": "^2.9.9"
"@types/react": "^18.2.8",
"@types/react-dom": "^18.2.4",
"@vitejs/plugin-react": "^4.0.0",
"eslint": "8.42.0",
"jest": "^29.5.0",
"prettier": "^2.8.8",
"vite": "^4.3.9"
}
}
1 change: 1 addition & 0 deletions examples/jest/test/abc.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable jest/no-export */
// eslint-disable-next-line import/prefer-default-export
export function myHelper() {}

Expand Down
16 changes: 8 additions & 8 deletions examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"lint": "eslint src --ext js,jsx,ts,tsx,mjs"
},
"dependencies": {
"react": "^18.0.0",
"react-dom": "^18.0.0"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@arcblock/eslint-config": "workspace:*",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@vitejs/plugin-react": "^1.3.0",
"eslint": "8.16.0",
"prettier": "^2.6.2",
"vite": "^2.9.9"
"@types/react": "^18.2.8",
"@types/react-dom": "^18.2.4",
"@vitejs/plugin-react": "^4.0.0",
"eslint": "8.42.0",
"prettier": "^2.8.8",
"vite": "^4.3.9"
}
}
3 changes: 3 additions & 0 deletions examples/react/src/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { echo } = require('./module-a');

echo();
3 changes: 3 additions & 0 deletions examples/react/src/lib/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { echo } from './module-b';

echo();
8 changes: 8 additions & 0 deletions examples/react/src/lib/module-a.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
echo() {
return 'Hello world';
},
say(name) {
return `Hello ${name}`;
},
};
6 changes: 6 additions & 0 deletions examples/react/src/lib/module-b.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function echo() {
return 'Hello world';
}
export function say(name) {
return `Hello ${name}`;
}
9 changes: 9 additions & 0 deletions examples/react/src/lib/promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function promiseFn() {
return new Promise(() => {});
}

async function main() {
await promiseFn();
}

main();
2 changes: 1 addition & 1 deletion examples/ts/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"printWidth": 120,
"tabWidth": 2,
"trailingComma": "es5",
"trailingComma": "all",
"semi": true,
"arrowParens": "always",
"singleQuote": true
Expand Down
16 changes: 8 additions & 8 deletions examples/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"base64-url": "^2.3.3",
"bn.js": "5.2.0",
"bn.js": "5.2.1",
"bs58": "^5.0.0",
"lodash": "^4.17.21",
"utf8": "^3.0.0"
Expand All @@ -22,15 +22,15 @@
"elliptic": "6.5.3"
},
"devDependencies": {
"@arcblock/eslint-config-ts": "^0.2.1",
"@arcblock/eslint-config-ts": "^0.2.3",
"@types/base64-url": "^2.2.0",
"@types/bn.js": "^5.1.0",
"@types/jest": "^28.1.0",
"@types/lodash": "^4.14.182",
"@types/node": "^17.0.38",
"@types/bn.js": "^5.1.1",
"@types/jest": "^29.5.2",
"@types/lodash": "^4.14.195",
"@types/node": "^20.2.5",
"@types/utf8": "^3.0.1",
"eslint": "^8.16.0",
"typescript": "^4.7.3"
"eslint": "^8.42.0",
"typescript": "^5.1.3"
},
"author": {
"name": "wangshijun",
Expand Down
1 change: 1 addition & 0 deletions examples/ts/src/constant.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// eslint-disable-next-line import/prefer-default-export
export const DEFAULT_TOKEN_DECIMAL = 18;
1 change: 1 addition & 0 deletions examples/ts/src/create-sorted-list.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
import uniq from 'lodash/uniq';
import flatten from 'lodash/flatten';

Expand Down
1 change: 1 addition & 0 deletions examples/ts/src/error.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
export class CustomError extends Error {
code: string;

Expand Down
1 change: 1 addition & 0 deletions examples/ts/src/get-list-field.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
import get from 'lodash/get';

export const getListField = (obj: $TSFixMe, key: string) => get(obj, `${key}List`) || get(obj, key) || [];
1 change: 1 addition & 0 deletions examples/ts/src/get-related-addr.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/* eslint-disable import/prefer-default-export */
export const getRelatedAddresses = (state: $TSFixMe) =>
[state.address].concat(state.migratedFrom || []).filter(Boolean);
8 changes: 4 additions & 4 deletions examples/ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export const numberToBN = (arg: string | number | BN) => {
}
throw new Error(
`[number-to-bn] while converting number ${JSON.stringify(
arg
)} to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported.`
arg,
)} to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported.`,
);
};

Expand Down Expand Up @@ -322,7 +322,7 @@ export const hexToBytes = (hex: $TSFixMe) => {
*/
export const toHex = (
value: string | number | boolean | BN | Uint8Array | Buffer | (number | { test: string })[] | { test: string },
returnType = false
returnType = false,
): string => {
if (isUint8Array(value) || Buffer.isBuffer(value)) {
return returnType ? 'bytes' : bytesToHex(value);
Expand Down Expand Up @@ -527,7 +527,7 @@ export function toUint8Array(v: $TSFixMe): Uint8Array {
vb = new Uint8Array(hexToBytes(toHex(v)));
} else {
throw new Error(
`Unsupported input type ${typeof v} detected for toBuffer, only Uint8Array/Buffer/Hex/Base58 are supported`
`Unsupported input type ${typeof v} detected for toBuffer, only Uint8Array/Buffer/Hex/Base58 are supported`,
);
}
return vb;
Expand Down
1 change: 1 addition & 0 deletions examples/ts/src/md5.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
import crypto from 'crypto';

export const md5 = (x: $TSFixMe) => crypto.createHash('md5').update(x).digest('hex');
9 changes: 9 additions & 0 deletions examples/ts/src/promise.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function promiseFn() {
return new Promise(() => {});
}

async function main() {
await promiseFn();
}

main();
1 change: 1 addition & 0 deletions examples/ts/src/ready.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
import EventEmitter from 'events';

export class Ready extends EventEmitter {
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"name": "root",
"private": true,
"scripts": {
"bump-version": "zx scripts/bump-version.mjs --quiet"
"lint": "pnpm --filter './examples/**' lint",
"update:deps": "taze latest -rw && pnpm dedupe",
"bump-version": "zx --quiet scripts/bump-version.mjs"
},
"devDependencies": {
"bumpp": "^7.2.0",
"zx": "^7.0.0"
"bumpp": "^9.1.1",
"zx": "^7.2.2"
},
"version": "0.2.3"
"version": "0.2.4"
}
8 changes: 8 additions & 0 deletions packages/eslint-config-base/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ const prettierRules = require('./prettier.js');
module.exports = {
extends: ['airbnb-base', 'plugin:prettier/recommended'],
plugins: ['unicorn', 'jest'],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.mjs'],
},
},
},
parserOptions: {
ecmaVersion: 2021,
},
Expand Down Expand Up @@ -40,6 +47,7 @@ module.exports = {
'class-methods-use-this': 'off',
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
'import/no-unresolved': ['error', { caseSensitive: true }],
'require-await': 'error',
'no-console': ['error', { allow: ['warn', 'error'] }],
'no-param-reassign': ['error', { props: false }],
'no-plusplus': 'off',
Expand Down
16 changes: 8 additions & 8 deletions packages/eslint-config-base/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@arcblock/eslint-config-base",
"version": "0.2.3",
"version": "0.2.4",
"description": "Arcblock's ESLint config base",
"author": "zhanghan <[email protected]>",
"homepage": "https://github.com/ArcBlock/eslint-config#readme",
Expand All @@ -18,15 +18,15 @@
},
"dependencies": {
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.8.7",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-unicorn": "^42.0.0"
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-unicorn": "^47.0.0"
},
"devDependencies": {
"eslint": "^8.17.0",
"prettier": "^2.7.1"
"eslint": "^8.42.0",
"prettier": "^2.8.8"
},
"peerDependencies": {
"eslint": "^8.17.0",
Expand Down
14 changes: 12 additions & 2 deletions packages/eslint-config-ts/base.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// follow javascript style from [here](https://github.com/airbnb/javascript)

const shared = require("./shared");
const shared = require('./shared');

module.exports = {
...shared,
extends: ["@arcblock/eslint-config-base", "airbnb-typescript/base"],
extends: ['@arcblock/eslint-config-base', 'airbnb-typescript/base'],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.mjs', '.ts'],
},
},
},
rules: {
'require-await': 'error',
},
};
14 changes: 12 additions & 2 deletions packages/eslint-config-ts/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// follow javascript style from [here](https://github.com/airbnb/javascript)

const shared = require("./shared");
const shared = require('./shared');

module.exports = {
...shared,
extends: ["@arcblock/eslint-config", "airbnb-typescript"],
extends: ['@arcblock/eslint-config', 'airbnb-typescript'],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.mjs', '.ts', '.tsx'],
},
},
},
rules: {
'require-await': 'error',
},
};
Loading

0 comments on commit 21a9977

Please sign in to comment.