disable specific linting rule

pull/5370/head
aniket-engg 3 years ago committed by Aniket
parent 80f30f94f7
commit 3dc300f73f
  1. 60
      libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx
  2. 2
      package.json

@ -1,15 +1,13 @@
import React, { useState, useRef, useEffect, ReactElement } from 'react' // eslint-disable-line import React, { useState, useRef, useEffect, ReactElement } from 'react' // eslint-disable-line
import { eachOfSeries } from 'async' // eslint-disable-line import { eachOfSeries } from 'async' // eslint-disable-line
import type Web3 from 'web3'
import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity'
import { Renderer } from '@remix-ui/renderer' // eslint-disable-line import { Renderer } from '@remix-ui/renderer' // eslint-disable-line
import { Toaster } from '@remix-ui/toaster' // eslint-disable-line import { Toaster } from '@remix-ui/toaster' // eslint-disable-line
import { format } from 'util' import { format } from 'util'
import './css/style.css' import './css/style.css'
const _paq = (window as any)._paq = (window as any)._paq || [] // eslint-disable-line const _paq = (window as any)._paq = (window as any)._paq || [] // eslint-disable-line @typescript-eslint/no-explicit-any
/* eslint-disable-next-line */
export interface SolidityUnitTestingProps { }
interface TestObject { interface TestObject {
fileName: string fileName: string
@ -18,7 +16,7 @@ interface TestObject {
interface TestResultInterface { interface TestResultInterface {
type: string type: string
value: any value: any // eslint-disable-line @typescript-eslint/no-explicit-any
time?: number time?: number
context?: string context?: string
errMsg?: string errMsg?: string
@ -28,7 +26,7 @@ interface TestResultInterface {
expected?: string | number expected?: string | number
location?: string location?: string
hhLogs?: [] hhLogs?: []
web3?: any web3?: Web3
debugTxHash?: string debugTxHash?: string
rendered?: boolean rendered?: boolean
} }
@ -36,11 +34,11 @@ interface TestResultInterface {
interface FinalResult { interface FinalResult {
totalPassing: number, totalPassing: number,
totalFailing: number, totalFailing: number,
totalTime: any, totalTime: any, // eslint-disable-line @typescript-eslint/no-explicit-any
errors: any[], errors: any[], // eslint-disable-line @typescript-eslint/no-explicit-any
} }
export const SolidityUnitTesting = (props: Record<string, any>) => { export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-disable-line @typescript-eslint/no-explicit-any
const { helper, testTab, initialPath } = props const { helper, testTab, initialPath } = props
const { testTabLogic } = testTab const { testTabLogic } = testTab
@ -73,14 +71,14 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
const isDebugging = useRef<boolean>(false) const isDebugging = useRef<boolean>(false)
const allTests = useRef<string[]>([]) const allTests = useRef<string[]>([])
const selectedTests = useRef<string[]>([]) const selectedTests = useRef<string[]>([])
const currentErrors:any = useRef([]) const currentErrors:any = useRef([]) // eslint-disable-line @typescript-eslint/no-explicit-any
const defaultPath = 'tests' const defaultPath = 'tests'
let areTestsRunning = false let areTestsRunning = false
let runningTestFileName: string let runningTestFileName: string
const filesContent: Record<string, Record<string, string>> = {} const filesContent: Record<string, Record<string, string>> = {}
const testsResultByFilename: Record<string, Record<string, Record<string, any>>> = {} const testsResultByFilename: Record<string, Record<string, Record<string, any>>> = {} // eslint-disable-line @typescript-eslint/no-explicit-any
const trimTestDirInput = (input: string) => { const trimTestDirInput = (input: string) => {
if (input.includes('/')) return input.split('/').map(e => e.trim()).join('/') if (input.includes('/')) return input.split('/').map(e => e.trim()).join('/')
@ -116,7 +114,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
selectedTests.current = [...allTests.current] selectedTests.current = [...allTests.current]
updateTestFileList() updateTestFileList()
if (!areTestsRunning) await updateRunAction(file) if (!areTestsRunning) await updateRunAction(file)
} catch (e: any) { } catch (e: any) { // eslint-disable-line @typescript-eslint/no-explicit-any
console.log(e) console.log(e)
setToasterMsg(e) setToasterMsg(e)
} }
@ -156,7 +154,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
}) })
testTab.fileManager.events.on('noFileSelected', () => { }) // eslint-disable-line testTab.fileManager.events.on('noFileSelected', () => { }) // eslint-disable-line
testTab.fileManager.events.on('currentFileChanged', async (file: string, provider: any) => await updateForNewCurrent(file)) testTab.fileManager.events.on('currentFileChanged', async (file: string) => await updateForNewCurrent(file))
}, []) // eslint-disable-line }, []) // eslint-disable-line
@ -166,7 +164,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
}) })
} }
const handleTestDirInput = async (e: any) => { const handleTestDirInput = async (e: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any
let testDirInput = trimTestDirInput(e.target.value) let testDirInput = trimTestDirInput(e.target.value)
testDirInput = helper.removeMultipleSlashes(testDirInput) testDirInput = helper.removeMultipleSlashes(testDirInput)
if (testDirInput !== '/') testDirInput = helper.removeTrailingSlashes(testDirInput) if (testDirInput !== '/') testDirInput = helper.removeTrailingSlashes(testDirInput)
@ -207,7 +205,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
} }
} }
const handleEnter = async (e: any) => { const handleEnter = async (e: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any
let inputPath = e.target.value let inputPath = e.target.value
inputPath = helper.removeMultipleSlashes(trimTestDirInput(inputPath)) inputPath = helper.removeMultipleSlashes(trimTestDirInput(inputPath))
setInputPathValue(inputPath) setInputPathValue(inputPath)
@ -238,14 +236,14 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
return fileName ? fileName.replace(/\//g, '_').replace(/\./g, '_') + testSuite : fileName return fileName ? fileName.replace(/\//g, '_').replace(/\./g, '_') + testSuite : fileName
} }
const startDebug = async (txHash: string, web3: any) => { const startDebug = async (txHash: string, web3: Web3) => {
isDebugging.current = true isDebugging.current = true
if (!await testTab.appManager.isActive('debugger')) await testTab.appManager.activatePlugin('debugger') if (!await testTab.appManager.isActive('debugger')) await testTab.appManager.activatePlugin('debugger')
testTab.call('menuicons', 'select', 'debugger') testTab.call('menuicons', 'select', 'debugger')
testTab.call('debugger', 'debug', txHash, web3) testTab.call('debugger', 'debug', txHash, web3)
} }
const printHHLogs = (logsArr: Record<string, any>[], testName: string) => { const printHHLogs = (logsArr: Record<string, any>[], testName: string) => { // eslint-disable-line @typescript-eslint/no-explicit-any
let finalLogs = `<b>${testName}:</b>\n` let finalLogs = `<b>${testName}:</b>\n`
for (const log of logsArr) { for (const log of logsArr) {
let formattedLog let formattedLog
@ -430,7 +428,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
} else if (contract === 'errors' && fileTestsResult['errors']) { } else if (contract === 'errors' && fileTestsResult['errors']) {
const errors = fileTestsResult['errors'] const errors = fileTestsResult['errors']
if (errors && errors.errors) { if (errors && errors.errors) {
errors.errors.forEach((err: any) => { errors.errors.forEach((err: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any
const errorCard: ReactElement = <Renderer message={err.formattedMessage || err.message} plugin={testTab} opt={{ type: err.severity, errorType: err.type }} /> const errorCard: ReactElement = <Renderer message={err.formattedMessage || err.message} plugin={testTab} opt={{ type: err.severity, errorType: err.type }} />
setTestsOutput(prevCards => ([...prevCards, errorCard])) setTestsOutput(prevCards => ([...prevCards, errorCard]))
}) })
@ -461,7 +459,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
} }
} }
const testCallback = (result: Record<string, any>) => { const testCallback = (result: Record<string, any>) => { // eslint-disable-line @typescript-eslint/no-explicit-any
if (result.filename) { if (result.filename) {
if (!testsResultByFilename[result.filename]) { if (!testsResultByFilename[result.filename]) {
testsResultByFilename[result.filename] = {} testsResultByFilename[result.filename] = {}
@ -479,7 +477,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
} }
} }
const resultsCallback = (_err: any, result: any, cb: any) => { const resultsCallback = (_err: any, result: any, cb: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any
// total stats for the test // total stats for the test
// result.passingNum // result.passingNum
// result.failureNum // result.failureNum
@ -487,7 +485,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
cb() cb()
} }
const updateFinalResult = (_errors: any, result: FinalResult|null, filename: string) => { const updateFinalResult = (_errors: any, result: FinalResult|null, filename: string) => { // eslint-disable-line @typescript-eslint/no-explicit-any
++readyTestsNumber ++readyTestsNumber
setReadyTestsNumber(readyTestsNumber) setReadyTestsNumber(readyTestsNumber)
if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) { if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) {
@ -524,7 +522,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
} }
} }
const runTest = (testFilePath: string, callback: any) => { const runTest = (testFilePath: string, callback: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any
isDebugging.current = false isDebugging.current = false
if (hasBeenStopped.current) { if (hasBeenStopped.current) {
updateFinalResult(null, null, testFilePath) updateFinalResult(null, null, testFilePath)
@ -550,14 +548,14 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
testTab.testRunner.runTestSources( testTab.testRunner.runTestSources(
runningTests, runningTests,
compilerConfig, compilerConfig,
(result: Record<string, any>) => testCallback(result), (result: Record<string, any>) => testCallback(result), // eslint-disable-line @typescript-eslint/no-explicit-any
(_err: any, result: any, cb: any) => resultsCallback(_err, result, cb), (_err: any, result: any, cb: any) => resultsCallback(_err, result, cb), // eslint-disable-line @typescript-eslint/no-explicit-any
deployCb, deployCb,
(error: any, result: any) => { (error: any, result: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any
updateFinalResult(error, result, testFilePath) updateFinalResult(error, result, testFilePath)
callback(error) callback(error)
}, (url: string, cb: any) => { }, (url: string, cb: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any
return testTab.contentImport.resolveAndSave(url).then((result: any) => cb(null, result)).catch((error: Error) => cb(error.message)) return testTab.contentImport.resolveAndSave(url).then((result: any) => cb(null, result)).catch((error: Error) => cb(error.message)) // eslint-disable-line @typescript-eslint/no-explicit-any
}, { testFilePath } }, { testFilePath }
) )
}).catch((error: Error) => { }).catch((error: Error) => {
@ -580,13 +578,13 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
if (!tests || !tests.length) return if (!tests || !tests.length) return
else setProgressBarHidden(false) else setProgressBarHidden(false)
_paq.push(['trackEvent', 'solidityUnitTesting', 'runTests']) _paq.push(['trackEvent', 'solidityUnitTesting', 'runTests'])
eachOfSeries(tests, (value: string, key: string, callback: any) => { eachOfSeries(tests, (value: string, key: string, callback: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any
if (hasBeenStopped.current) return if (hasBeenStopped.current) return
runTest(value, callback) runTest(value, callback)
}) })
} }
const updateRunAction = async (currentFile: any = null) => { const updateRunAction = async (currentFile: any = null) => { // eslint-disable-line @typescript-eslint/no-explicit-any
const isSolidityActive = await testTab.appManager.isActive('solidity') const isSolidityActive = await testTab.appManager.isActive('solidity')
if (!isSolidityActive || !selectedTests.current?.length) { if (!isSolidityActive || !selectedTests.current?.length) {
// setDisableRunButton(true) // setDisableRunButton(true)
@ -627,7 +625,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
} else setCheckSelectAll(false) } else setCheckSelectAll(false)
} }
const checkAll = (event: any) => { const checkAll = (event: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any
testFiles.forEach((testFileObj) => testFileObj.checked = event.target.checked) testFiles.forEach((testFileObj) => testFileObj.checked = event.target.checked)
setTestFiles(testFiles) setTestFiles(testFiles)
setCheckSelectAll(event.target.checked) setCheckSelectAll(event.target.checked)
@ -698,7 +696,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
title="Generate sample test file." title="Generate sample test file."
disabled={disableGenerateButton} disabled={disableGenerateButton}
onClick={async () => { onClick={async () => {
testTabLogic.generateTestFile((err:any) => { if (err) setToasterMsg(err)}) testTabLogic.generateTestFile((err:any) => { if (err) setToasterMsg(err)}) // eslint-disable-line @typescript-eslint/no-explicit-any
await updateForNewCurrent() await updateForNewCurrent()
}} }}
> >

@ -45,7 +45,7 @@
"workspace-schematic": "nx workspace-schematic", "workspace-schematic": "nx workspace-schematic",
"dep-graph": "nx dep-graph", "dep-graph": "nx dep-graph",
"help": "nx help", "help": "nx help",
"lint:libs": "nx run-many --target=lint --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd,remix-ui-tree-view,remix-ui-modal-dialog,remix-ui-toaster,remix-ui-helper,remix-ui-debugger-ui,remix-ui-workspace,remix-ui-static-analyser,remix-ui-checkbox,remix-ui-settings,remix-core-plugin,remix-ui-renderer,remix-ui-publish-to-storage,remix-ui-solidity-compiler,remix-ui-plugin-manager,remix-ui-terminal,remix-ui-editor,remix-ui-app,remix-ui-tabs", "lint:libs": "nx run-many --target=lint --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd,remix-ui-tree-view,remix-ui-modal-dialog,remix-ui-toaster,remix-ui-helper,remix-ui-debugger-ui,remix-ui-workspace,remix-ui-static-analyser,remix-ui-checkbox,remix-ui-settings,remix-core-plugin,remix-ui-renderer,remix-ui-publish-to-storage,remix-ui-solidity-compiler,solidity-unit-testing,remix-ui-plugin-manager,remix-ui-terminal,remix-ui-editor,remix-ui-app,remix-ui-tabs",
"build:libs": "nx run-many --target=build --parallel=false --with-deps=true --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd", "build:libs": "nx run-many --target=build --parallel=false --with-deps=true --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd",
"test:libs": "nx run-many --target=test --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd", "test:libs": "nx run-many --target=test --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd",
"publish:libs": "npm run build:libs && lerna publish --skip-git && npm run bumpVersion:libs", "publish:libs": "npm run build:libs && lerna publish --skip-git && npm run bumpVersion:libs",

Loading…
Cancel
Save