remove tslint (using eslint now)

This commit is contained in:
Alexey 2020-10-19 15:02:47 +03:00
parent 402732a84b
commit 305072f198
10 changed files with 751 additions and 125 deletions

17
.eslintrc.js Normal file

@ -0,0 +1,17 @@
module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
},
extends: [
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
rules: {
indent: ['error', 2],
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
},
};

@ -17,11 +17,7 @@ jobs:
node-version: 12
- run: yarn install --frozen-lockfile
- run: yarn test
- name: TSLint checks
uses: mooyoul/tslint-actions@v1.1.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
project: tsconfig.json
- run: yarn lint
publish:
runs-on: ubuntu-latest

@ -1,6 +1,8 @@
{
"arrowParens": "avoid",
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 110,
"trailingComma": "all"
"tabWidth": 2,
"arrowParens": "avoid"
}

@ -12,12 +12,12 @@
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"scripts": {
"test": "mocha --timeout 30000 -r ts-node/register tests/*.test.ts",
"test": "mocha -r ts-node/register --timeout 30000 --exit src tests/*.test.ts",
"build": "tsc",
"tslint": "tslint -p tsconfig.json",
"prettier:check": "npx prettier --check . --config .prettierrc",
"prettier:fix": "npx prettier --write . --config .prettierrc",
"lint": "yarn tslint && yarn prettier:check"
"eslint": "eslint '*/**/*.{js,ts}' --quiet --fix",
"prettier:check": "prettier --check . --config .prettierrc",
"prettier:fix": "prettier --write . --config .prettierrc",
"lint": "yarn eslint && yarn prettier:check"
},
"author": "Alexey Pertsev <alexey@peppersec.com> (https://peppersec.com)",
"keywords": [
@ -29,18 +29,21 @@
"license": "MIT",
"devDependencies": {
"@types/chai": "^4.2.11",
"@types/chai-as-promised": "^7.1.3",
"@types/mocha": "^7.0.2",
"@types/mockery": "^1.4.29",
"@types/node": "^14.0.5",
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/parser": "^4.4.1",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"eslint": "^7.11.0",
"eslint-config-prettier": "^6.13.0",
"eslint-plugin-prettier": "^3.1.4",
"mocha": "^7.2.0",
"mockery": "^2.1.0",
"prettier": "^2.1.2",
"ts-node": "^8.10.1",
"tslint": "^6.1.2",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.3.0",
"typescript": "^4.0.3"
},
"dependencies": {

@ -1,6 +1,6 @@
import axios from 'axios';
import config from './config';
import { GasPrice, OffChainOracle, OnChainOracle, Config, GasPriceKey } from './types';
import { GasPrice, OffChainOracle, OnChainOracle, Config, GasPriceKey, Options } from './types';
import BigNumber from 'bignumber.js';
export class GasPriceOracle {
@ -12,7 +12,7 @@ export class GasPriceOracle {
timeout: 10000,
};
constructor(options: Config) {
constructor(options?: Options) {
if (options) {
Object.assign(this.configuration, options);
}
@ -46,7 +46,7 @@ export class GasPriceOracle {
}
}
async fetchGasPricesOffChain(): Promise<GasPrice> {
for (let oracle of Object.values(this.offChainOracles)) {
for (const oracle of Object.values(this.offChainOracles)) {
try {
return await this.askOracle(oracle);
} catch (e) {
@ -57,9 +57,9 @@ export class GasPriceOracle {
throw new Error('All oracles are down. Probably a network error.');
}
async fetchMedianGasPriceOffChain() {
async fetchMedianGasPriceOffChain(): Promise<GasPrice> {
const promises: Promise<GasPrice>[] = [];
for (let oracle of Object.values(this.offChainOracles) as Array<OffChainOracle>) {
for (const oracle of Object.values(this.offChainOracles) as Array<OffChainOracle>) {
promises.push(this.askOracle(oracle));
}
@ -111,7 +111,7 @@ export class GasPriceOracle {
}
async fetchGasPricesOnChain(): Promise<number> {
for (let oracle of Object.values(this.onChainOracles)) {
for (const oracle of Object.values(this.onChainOracles)) {
const { name, callData, contract, denominator, rpc } = oracle;
const rpcUrl = rpc || this.configuration.defaultRpc;
const body = {

@ -22,7 +22,9 @@ export type GasPrice = {
export type GasPriceKey = 'instant' | 'fast' | 'standard' | 'low';
export interface Config {
export type Options = {
defaultRpc?: string;
timeout?: number;
}
};
export type Config = Required<Options>;

@ -1,15 +1,17 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-var-requires */
import { GasPrice } from '../src/types';
import mockery from 'mockery';
import chai from 'chai';
import { onChainOracles } from '../src/config';
const { GasPriceOracle } = require('../src/index');
import { GasPriceOracle } from '../src/index';
chai.use(require('chai-as-promised'));
chai.should();
let oracle = new GasPriceOracle();
before('before', function () {
let axiosMock = {
const axiosMock = {
get: () => {
throw new Error('axios GET method is mocked for tests');
},
@ -189,7 +191,7 @@ describe('median', function () {
describe('fetchMedianGasPriceOffChain', function () {
it('should work', async function () {
let gas: GasPrice = await oracle.fetchMedianGasPriceOffChain();
const gas: GasPrice = await oracle.fetchMedianGasPriceOffChain();
gas.instant.should.be.a('number');
gas.fast.should.be.a('number');
gas.standard.should.be.a('number');

@ -14,6 +14,7 @@
"strictPropertyInitialization": false /* Enable strict checking of property initialization in classes. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
"declaration": true /* Generates corresponding '.d.ts' file. */,
"forceConsistentCasingInFileNames": true,
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
@ -61,11 +62,7 @@
/* Experimental Options */
"experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */,
"plugins": [
{
"name": "typescript-tslint-plugin"
}
]
"plugins": []
},
"include": ["src"],
"exclude": ["node_modules", "tests"]

@ -1,12 +0,0 @@
{
"extends": "tslint-config-prettier",
"defaultSeverity": "error",
"rules": {
"semicolon": [true, "always"],
"space-before-function-paren": [
true,
{ "anonymous": "always", "named": "never", "asyncArrow": "always" }
],
"type-literal-delimiter": true
}
}

783
yarn.lock

File diff suppressed because it is too large Load Diff