remix-solidity linting fixed

pull/5370/head
aniket-engg 4 years ago
parent b9016e34be
commit 6518d35657
  1. 5
      libs/remix-solidity/.eslintrc
  2. 7
      libs/remix-solidity/src/compiler/compiler-input.ts
  3. 6
      libs/remix-solidity/src/compiler/compiler-worker.ts
  4. 64
      libs/remix-solidity/src/compiler/compiler.ts
  5. 4
      libs/remix-solidity/src/compiler/txHelper.ts
  6. 89
      libs/remix-solidity/src/compiler/types.ts
  7. 2
      package.json

@ -1,9 +1,8 @@
{
"extends": "../../.eslintrc",
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-unused-vars": "off"
"dot-notation": "off",
"no-unused-vars": "off"
},
"env": {
"browser": true,

@ -14,8 +14,8 @@ export default (sources: Source, opts: CompilerInputOptions): string => {
libraries: opts.libraries,
outputSelection: {
'*': {
'': [ 'ast' ],
'*': [ 'abi', 'metadata', 'devdoc', 'userdoc', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates', 'evm.assembly' ]
'': ['ast'],
'*': ['abi', 'metadata', 'devdoc', 'userdoc', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates', 'evm.assembly']
}
}
}
@ -27,8 +27,7 @@ export default (sources: Source, opts: CompilerInputOptions): string => {
o.language = opts.language
}
if (opts.language === 'Yul' && o.settings.optimizer.enabled) {
if (!o.settings.optimizer.details)
o.settings.optimizer.details = {}
if (!o.settings.optimizer.details) { o.settings.optimizer.details = {} }
o.settings.optimizer.details.yul = true
}
return JSON.stringify(o)

@ -17,14 +17,14 @@ export default function (self) { // eslint-disable-line @typescript-eslint/expli
// NOTE: workaround some browsers?
self.Module = undefined
compileJSON = null
//importScripts() method of synchronously imports one or more scripts into the worker's scope
// importScripts() method of synchronously imports one or more scripts into the worker's scope
self.importScripts(data.data)
const compiler: solc = solc(self.Module)
compileJSON = (input) => {
try {
const missingInputsCallback = (path) => {
missingInputs.push(path)
return { 'error': 'Deferred import' }
return { error: 'Deferred import' }
}
return compiler.compile(input, { import: missingInputsCallback })
} catch (exception) {
@ -40,7 +40,7 @@ export default function (self) { // eslint-disable-line @typescript-eslint/expli
case 'compile':
missingInputs.length = 0
if(data.input && compileJSON) {
if (data.input && compileJSON) {
self.postMessage({
cmd: 'compiled',
job: data.job,

@ -4,11 +4,13 @@ import { update } from 'solc/abi'
import * as webworkify from 'webworkify-webpack'
import compilerInput from './compiler-input'
import EventManager from '../lib/eventManager'
import { default as txHelper } from './txHelper';
import { Source, SourceWithTarget, MessageFromWorker, CompilerState, CompilationResult,
import txHelper from './txHelper'
import {
Source, SourceWithTarget, MessageFromWorker, CompilerState, CompilationResult,
visitContractsCallbackParam, visitContractsCallbackInterface, CompilationError,
gatherImportsCallbackInterface,
isFunctionDescription } from './types'
isFunctionDescription
} from './types'
/*
trigger compilationFinished, compilerLoaded, compilationStarted, compilationDuration
@ -53,7 +55,7 @@ export class Compiler {
* @param value value of key in CompilerState
*/
set <K extends keyof CompilerState>(key: K, value: CompilerState[K]): void {
set <K extends keyof CompilerState> (key: K, value: CompilerState[K]): void {
this.state[key] = value
if (key === 'runs') this.state['runs'] = parseInt(value)
}
@ -68,9 +70,8 @@ export class Compiler {
this.gatherImports(files, missingInputs, (error, input) => {
if (error) {
this.state.lastCompilationResult = null
this.event.trigger('compilationFinished', [false, {'error': { formattedMessage: error, severity: 'error' }}, files])
} else if(this.state.compileJSON && input)
this.state.compileJSON(input)
this.event.trigger('compilationFinished', [false, { error: { formattedMessage: error, severity: 'error' } }, files])
} else if (this.state.compileJSON && input) { this.state.compileJSON(input) }
})
}
@ -111,9 +112,9 @@ export class Compiler {
}
let result: CompilationResult = {}
try {
if(source && source.sources) {
const {optimize, runs, evmVersion, language} = this.state
const input = compilerInput(source.sources, {optimize, runs, evmVersion, language})
if (source && source.sources) {
const { optimize, runs, evmVersion, language } = this.state
const input = compilerInput(source.sources, { optimize, runs, evmVersion, language })
result = JSON.parse(compiler.compile(input, { import: missingInputsCallback }))
}
} catch (exception) {
@ -138,7 +139,7 @@ export class Compiler {
const checkIfFatalError = (error: CompilationError) => {
// Ignore warnings and the 'Deferred import' error as those are generated by us as a workaround
const isValidError = (error.message && error.message.includes('Deferred import')) ? false : error.severity !== 'warning'
if(isValidError) noFatalErrors = false
if (isValidError) noFatalErrors = false
}
if (data.error) checkIfFatalError(data.error)
if (data.errors) data.errors.forEach((err) => checkIfFatalError(err))
@ -151,9 +152,8 @@ export class Compiler {
this.internalCompile(source.sources, missingInputs)
} else {
data = this.updateInterface(data)
if(source)
{
source.target = this.state.target;
if (source) {
source.target = this.state.target
this.state.lastCompilationResult = {
data: data,
source: source
@ -183,9 +183,9 @@ export class Compiler {
}
let result: CompilationResult = {}
try {
if(source && source.sources) {
const {optimize, runs, evmVersion, language} = this.state
const input = compilerInput(source.sources, {optimize, runs, evmVersion, language})
if (source && source.sources) {
const { optimize, runs, evmVersion, language } = this.state
const input = compilerInput(source.sources, { optimize, runs, evmVersion, language })
result = JSON.parse(remoteCompiler.compile(input, { import: missingInputsCallback }))
}
} catch (exception) {
@ -257,16 +257,16 @@ export class Compiler {
const data: MessageFromWorker = msg.data
switch (data.cmd) {
case 'versionLoaded':
if(data.data) this.onCompilerLoaded(data.data)
if (data.data) this.onCompilerLoaded(data.data)
break
case 'compiled':
{
let result: CompilationResult
if(data.data && data.job !== undefined && data.job >= 0) {
if (data.data && data.job !== undefined && data.job >= 0) {
try {
result = JSON.parse(data.data)
} catch (exception) {
result = { error : { formattedMessage: 'Invalid JSON output from the compiler: ' + exception }}
result = { error: { formattedMessage: 'Invalid JSON output from the compiler: ' + exception } }
}
let sources: SourceWithTarget = {}
if (data.job in jobs !== undefined) {
@ -281,17 +281,17 @@ export class Compiler {
})
this.state.worker.addEventListener('error', (msg: Record <'data', MessageFromWorker>) => {
this.onCompilationFinished({ error: { formattedMessage: 'Worker error: ' + msg.data }})
this.onCompilationFinished({ error: { formattedMessage: 'Worker error: ' + msg.data } })
})
this.state.compileJSON = (source: SourceWithTarget) => {
if(source && source.sources) {
const {optimize, runs, evmVersion, language} = this.state
jobs.push({sources: source})
if (source && source.sources) {
const { optimize, runs, evmVersion, language } = this.state
jobs.push({ sources: source })
this.state.worker.postMessage({
cmd: 'compile',
job: jobs.length - 1,
input: compilerInput(source.sources, {optimize, runs, evmVersion, language})
input: compilerInput(source.sources, { optimize, runs, evmVersion, language })
})
}
}
@ -340,8 +340,7 @@ export class Compiler {
}
return
}
if(cb)
cb(null, { 'sources': files })
if (cb) { cb(null, { sources: files }) }
}
/**
@ -366,12 +365,12 @@ export class Compiler {
// yul compiler does not return any abi,
// we default to accept the fallback function (which expect raw data as argument).
contract.object.abi.push({
'payable': true,
'stateMutability': 'payable',
'type': 'fallback'
payable: true,
stateMutability: 'payable',
type: 'fallback'
})
}
if(data && data.contracts && this.state.currentVersion) {
if (data && data.contracts && this.state.currentVersion) {
const version = this.truncateVersion(this.state.currentVersion)
data.contracts[contract.file][contract.name].abi = update(version, contract.object.abi)
// if "constant" , payable must not be true and stateMutability must be view.
@ -379,7 +378,7 @@ export class Compiler {
for (const item of data.contracts[contract.file][contract.name].abi) {
if (isFunctionDescription(item) && item.constant) {
item.payable = false
item.stateMutability = 'view';
item.stateMutability = 'view'
}
}
}
@ -457,4 +456,3 @@ export class Compiler {
return null
}
}

@ -9,7 +9,7 @@ export default {
* @param contracts 'contracts' object from last compilation result
*/
getContract: (contractName: string, contracts: CompilationResult["contracts"]) : Record<string, any> | null => {
getContract: (contractName: string, contracts: CompilationResult['contracts']) : Record<string, any> | null => {
for (const file in contracts) {
if (contracts[file][contractName]) {
return { object: contracts[file][contractName], file: file }
@ -24,7 +24,7 @@ export default {
* @param cb - callback
*/
visitContracts: (contracts: CompilationResult["contracts"], cb: visitContractsCallbackInterface) : void => {
visitContracts: (contracts: CompilationResult['contracts'], cb: visitContractsCallbackInterface) : void => {
for (const file in contracts) {
for (const name in contracts[file]) {
const param: visitContractsCallbackParam = {

@ -129,7 +129,6 @@ export interface CompilerInput {
}
}
export interface Source {
[fileName: string]:
{
@ -221,11 +220,11 @@ export interface CompilationResult {
}
}
///////////
// ERROR //
///////////
/// ////////
// ERROR //
/// ////////
export interface CompilationError {
export interface CompilationError {
/** Location within the source file */
sourceLocation?: {
file: string
@ -258,20 +257,20 @@ export interface CompilationResult {
| 'FatalError'
| 'Warning'
////////////
// SOURCE //
////////////
export interface CompilationSource {
/// /////////
// SOURCE //
/// /////////
export interface CompilationSource {
/** Identifier of the source (used in source maps) */
id: number
/** The AST object */
ast: AstNode
}
/////////
// AST //
/////////
export interface AstNode {
/// //////
// AST //
/// //////
export interface AstNode {
absolutePath?: string
exportedSymbols?: Record<string, unknown>
id: number
@ -286,7 +285,7 @@ export interface CompilationResult {
[x: string]: any
}
export interface AstNodeAtt {
export interface AstNodeAtt {
operator?: string
string?: null
type?: string
@ -300,10 +299,10 @@ export interface CompilationResult {
[x: string]: any
}
//////////////
// CONTRACT //
//////////////
export interface CompiledContract {
/// ///////////
// CONTRACT //
/// ///////////
export interface CompiledContract {
/** The Ethereum Contract ABI. If empty, it is represented as an empty array. */
abi: ABIDescription[]
// See the Metadata Output documentation (serialised JSON string)
@ -349,18 +348,18 @@ export interface CompilationResult {
}
}
/////////
// ABI //
/////////
export type ABIDescription = FunctionDescription | EventDescription
/// //////
// ABI //
/// //////
export type ABIDescription = FunctionDescription | EventDescription
export const isFunctionDescription = (item: ABIDescription): item is FunctionDescription =>
(item as FunctionDescription).stateMutability !== undefined;
export const isFunctionDescription = (item: ABIDescription): item is FunctionDescription =>
(item as FunctionDescription).stateMutability !== undefined
export const isEventDescription = (item: ABIDescription): item is EventDescription =>
(item as EventDescription).type === 'event';
export const isEventDescription = (item: ABIDescription): item is EventDescription =>
(item as EventDescription).type === 'event'
export interface FunctionDescription {
export interface FunctionDescription {
/** Type of the method. default is 'function' */
type?: 'function' | 'constructor' | 'fallback' | 'receive'
/** The name of the function. Constructor and fallback function never have name */
@ -377,7 +376,7 @@ export interface CompilationResult {
constant?: boolean
}
export interface EventDescription {
export interface EventDescription {
type: 'event'
name: string
inputs: ABIParameter &
@ -389,7 +388,7 @@ export interface CompilationResult {
anonymous: boolean
}
export interface ABIParameter {
export interface ABIParameter {
/** The name of the parameter */
name: string
/** The canonical type of the parameter */
@ -398,7 +397,7 @@ export interface CompilationResult {
components?: ABIParameter[]
}
export type ABITypeParameter =
export type ABITypeParameter =
| 'uint'
| 'uint[]' // TODO : add <M>
| 'int'
@ -419,38 +418,38 @@ export interface CompilationResult {
| 'tuple[]'
| string // Fallback
///////////////////////////
// NATURAL SPECIFICATION //
///////////////////////////
/// ////////////////////////
// NATURAL SPECIFICATION //
/// ////////////////////////
// Userdoc
export interface UserDocumentation {
// Userdoc
export interface UserDocumentation {
methods: UserMethodList
notice: string
}
export type UserMethodList = {
export type UserMethodList = {
[functionIdentifier: string]: UserMethodDoc
} & {
'constructor'?: string
}
export interface UserMethodDoc {
export interface UserMethodDoc {
notice: string
}
// Devdoc
export interface DeveloperDocumentation {
// Devdoc
export interface DeveloperDocumentation {
author: string
title: string
details: string
methods: DevMethodList
}
export interface DevMethodList {
export interface DevMethodList {
[functionIdentifier: string]: DevMethodDoc
}
export interface DevMethodDoc {
export interface DevMethodDoc {
author: string
details: string
return: string
@ -459,10 +458,10 @@ export interface CompilationResult {
}
}
//////////////
// BYTECODE //
//////////////
export interface BytecodeObject {
/// ///////////
// BYTECODE //
/// ///////////
export interface BytecodeObject {
/** The bytecode as a hex string. */
object: string
/** Opcodes list */

@ -41,7 +41,7 @@
"workspace-schematic": "nx workspace-schematic",
"dep-graph": "nx dep-graph",
"help": "nx help",
"lint:libs": "nx run-many --target=lint --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remixd,remix-ui-tree-view,remix-ui-modal-dialog,remix-ui-toaster,remix-ui-file-explorer,remix-ui-debugger-ui",
"lint:libs": "nx run-many --target=lint --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remixd,remix-ui-tree-view,remix-ui-modal-dialog,remix-ui-toaster,remix-ui-file-explorer,remix-ui-debugger-ui",
"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",
"publish:libs": "npm run build:libs & lerna publish --skip-git & npm run bumpVersion:libs",

Loading…
Cancel
Save