refactor(tauri.js): Fix ESLint errors (#398)

* refactor(tauri.js): Fix ESLint errors

* fix(tauri.js): Disable space-before-function-paren

This conflicts with @typescript-eslint/space-before-function-paren. See https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/space-before-function-paren.md#how-to-use

* refactor(tauri.js): Change requires to imports

* fix(tauri.js): Suppress security/detect-non-literal-fs-filename in src/api/info.ts

* fix(tauri.js): Suppress @typescript-eslint/restrict-template-expressions in some cases

* fix(tauri.js): Suppress ESLint warnings in src/template/index.ts

- Suppress security/detect-object-injection (false positives)
- Suppress @typescript-eslint/no-dynamic-delete
This commit is contained in:
Rajiv Shah 2020-02-08 10:17:27 -05:00 committed by GitHub
parent 38858ab8d8
commit 5906b5ca5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 26 additions and 10 deletions

View File

@ -47,8 +47,9 @@ module.exports = {
'security/detect-object-injection': 'warn',
'security/detect-possible-timing-attacks': 'error',
'security/detect-pseudoRandomBytes': 'error',
'space-before-function-paren': 'off',
'@typescript-eslint/strict-boolean-expressions': 0,
'space-before-function-paren': [
'@typescript-eslint/space-before-function-paren': [
'error',
{
asyncArrow: 'always',

View File

@ -1,7 +1,7 @@
import { TauriConfig } from 'types'
import merge from 'webpack-merge'
import Runner from '../runner'
const getTauriConfig = require('../helpers/tauri-config')
import getTauriConfig from '../helpers/tauri-config'
module.exports = async (config: TauriConfig): Promise<void> => {
const tauri = new Runner()

View File

@ -1,7 +1,7 @@
import { TauriConfig } from 'types'
import merge from 'webpack-merge'
import Runner from '../runner'
const getTauriConfig = require('../helpers/tauri-config')
import getTauriConfig from '../helpers/tauri-config'
module.exports = async (config: TauriConfig): Promise<void> => {
const tauri = new Runner()

View File

@ -14,6 +14,7 @@ interface DirInfo {
children?: DirInfo[]
}
/* eslint-disable security/detect-non-literal-fs-filename */
function dirTree(filename: string): DirInfo {
const stats = fs.lstatSync(filename)
const info: DirInfo = {
@ -92,6 +93,7 @@ function printAppInfo(tauriDir: string): void {
// @ts-ignore
const tauriTomlContents = toml.parse(tauriTomlFile)
return chalk.green(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`${tauriTomlContents.package.version} (from source)`
)
} catch (_) {}
@ -173,10 +175,12 @@ module.exports = () => {
printInfo({ key: 'App directory structure', section: true })
const tree = dirTree(appDir)
for (const artifact of tree.children || []) {
for (const artifact of tree.children ?? []) {
if (artifact.type === 'folder') {
console.log(`/${artifact.name}`)
}
}
printAppInfo(tauriDir)
}
/* eslint-enable security/detect-non-literal-fs-filename */

View File

@ -172,6 +172,7 @@ const spinner = (): NodeJS.Timeout => {
}, 500)
}
/* eslint-disable @typescript-eslint/restrict-template-expressions */
const tauricon = (exports.tauricon = {
validate: async function(src: string, target: string) {
await validate(src, target)
@ -226,7 +227,7 @@ const tauricon = (exports.tauricon = {
try {
const pngImage = sharpSrc.resize(pvar[1], pvar[1])
if (pvar[2]) {
const rgb = hexToRgb(options.background_color) || {
const rgb = hexToRgb(options.background_color) ?? {
r: undefined,
g: undefined,
b: undefined
@ -291,7 +292,7 @@ const tauricon = (exports.tauricon = {
) {
let output
let block = false
const rgb = hexToRgb(options.background_color) || {
const rgb = hexToRgb(options.background_color) ?? {
r: undefined,
g: undefined,
b: undefined
@ -480,6 +481,7 @@ const tauricon = (exports.tauricon = {
}
}
})
/* eslint-enable @typescript-eslint/restrict-template-expressions */
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {

View File

@ -14,6 +14,7 @@ export default (banner: string, color: string = 'green') => {
console.log(
// TODO: proper typings for color and banner
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
` ${chalk[String(color)](String(banner))} ${msg} ${chalk.green(`+${ms(diff)}`)}`
)
} else {

View File

@ -25,10 +25,11 @@ export const spawn = (
runner.on('close', code => {
log()
if (code) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
log(`Command "${cmd}" failed with exit code: ${code}`)
}
onClose && onClose(code)
onClose?.(code)
})
return runner.pid
@ -51,13 +52,15 @@ export const spawnSync = (
cwd
})
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
if (runner.status || runner.error) {
warn()
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
warn(`⚠️ Command "${cmd}" failed with exit code: ${runner.status}`)
if (runner.status === null) {
warn(`⚠️ Please globally install "${cmd}"`)
}
onFail && onFail()
onFail?.()
process.exit(1)
}
}

View File

@ -7,7 +7,7 @@ import * as appPaths from './app-paths'
const error = logger('ERROR:', 'red')
module.exports = (cfg: Partial<TauriConfig>): TauriConfig => {
const getTauriConfig = (cfg: Partial<TauriConfig>): TauriConfig => {
const pkgPath = appPaths.resolve.app('package.json')
const tauriConfPath = appPaths.resolve.tauri('tauri.conf.json')
if (!existsSync(pkgPath)) {
@ -69,3 +69,5 @@ module.exports = (cfg: Partial<TauriConfig>): TauriConfig => {
return config
}
export default getTauriConfig

View File

@ -34,9 +34,12 @@ const injectConfFile = (
}
Object.keys(finalConf).forEach(key => {
// Options marked `null` should be removed
/* eslint-disable security/detect-object-injection */
if (finalConf[key] === null) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete finalConf[key]
}
/* eslint-enable security/detect-object-injection */
})
writeFileSync(path, JSON.stringify(finalConf, undefined, 2))
} catch (e) {

View File

@ -38,7 +38,7 @@ export interface TauriConfig {
}
edge: {
active: boolean
},
}
inliner: {
active: boolean
}