Skip to content

Commit

Permalink
Fix eslint violations
Browse files Browse the repository at this point in the history
Some rules have been disabled as they either weren't handled by the old
tslint config or tslint just wasn't configured before.
  • Loading branch information
krispenney committed Oct 7, 2022
1 parent 87ab342 commit e1a5eb4
Show file tree
Hide file tree
Showing 52 changed files with 138 additions and 70 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ module.exports = {
env: {
es2017: true
},
ignorePatterns: ["*.d.ts", "styles.js", "*.tab.js"],
overrides: [
{
plugins: ['@typescript-eslint'],
files: ['*.ts', '*.tsx'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
Expand All @@ -20,9 +22,12 @@ module.exports = {
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-unsafe-argument': 0,
'@typescript-eslint/no-unsafe-assignment': 0,
'@typescript-eslint/no-unsafe-call': 0,
'@typescript-eslint/no-unsafe-member-access': 0
'@typescript-eslint/no-unsafe-member-access': 0,
'@typescript-eslint/no-unsafe-return': 0,
'@typescript-eslint/restrict-template-expressions': 0,
}
},
]
Expand Down
Binary file modified examples/tabs/starter-basic/starter-basic.tgz
Binary file not shown.
3 changes: 2 additions & 1 deletion packages/@misk/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"clean": "rm -rf lib",
"ci-build": "npm run-script clean && npm run-script lib",
"lib": "npm run-script build",
"lint": "prettier --write --config package.json .",
"lint": "prettier --write --config package.json . && npm run eslint",
"eslint": "eslint .",
"start": "node lib/src/index.js",
"watch": "./node_modules/.bin/tsc -w",
"build": "npm run-script clean && npm run-script buildcli && npm run test",
Expand Down
3 changes: 2 additions & 1 deletion packages/@misk/cli/plop-templates/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"clean-build-files": "rm .hash package-lock.json package.json tsconfig.json webpack.config.js",
"lib": "cross-env NODE_ENV=production webpack",
"dev-lib": "cross-env NODE_ENV=development webpack",
"lint": "prettier --write --config package.json .",
"lint": "prettier --write --config package.json . && npm run eslint",
"eslint": "eslint .",
"prebuild": "miskweb prebuild && npm run-script lint",
"reinstall": "rm -rf node_modules && npm run-script install",
"start": "npm run-script prebuild && cross-env NODE_ENV=development webpack-dev-server",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
mapStateToProps
} from "src/ducks"

/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
const TabContainer = (props: IState & IDispatchProps) => {
const tag = "LoadData"
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/@misk/cli/src/commands/auto-pin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const handlerFn = async (...args: any) => {
)
)
}
generateMiskTabJson(dir, { ...miskTab, version: masterDeps.miskWebNPM })
await generateMiskTabJson(dir, { ...miskTab, version: masterDeps.miskWebNPM })
execute(npmRunScript("prebuild", true), ...args)
} else {
logDebug(
Expand Down
1 change: 1 addition & 0 deletions packages/@misk/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const desc = "run a fast Webpack development build\n"
export const handlerFn = async (...args: any) => {
logDebug(command, desc)
execute(npmRunScript(command, true), ...args)
return Promise.resolve()
}
export const handler = async (yargs: any) => handleCommand(yargs, handlerFn)
1 change: 1 addition & 0 deletions packages/@misk/cli/src/commands/ci-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const desc = "npm install, then Webpack production build, tests\n"
export const handlerFn = async (...args: any) => {
logDebug(command, desc)
execute(npmRunScript(command, true), ...args)
return Promise.resolve()
}
export const handler = async (yargs: any) => handleCommand(yargs, handlerFn)
1 change: 1 addition & 0 deletions packages/@misk/cli/src/commands/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const desc = "remove lib directory and other temporary files\n"
export const handlerFn = async (...args: any) => {
logDebug(command, desc)
execute(npmRunScript(command, true), ...args)
return Promise.resolve()
}
export const handler = async (yargs: any) => handleCommand(yargs, handlerFn)
1 change: 1 addition & 0 deletions packages/@misk/cli/src/commands/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const desc = "install node_modules dependencies\n"
export const handlerFn = async (...args: any) => {
logDebug(command, desc)
execute("npm install", ...args)
return Promise.resolve()
}
export const handler = async (yargs: any) => handleCommand(yargs, handlerFn)
1 change: 1 addition & 0 deletions packages/@misk/cli/src/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const desc = "use prettier to lint all files\n"
export const handlerFn = async (...args: any) => {
logDebug(command, desc)
execute(npmRunScript(command, true), ...args)
return Promise.resolve()
}
export const handler = async (yargs: any) => handleCommand(yargs, handlerFn)
1 change: 1 addition & 0 deletions packages/@misk/cli/src/commands/misk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ sourceSets {
http://localhost:8080/_admin/${miskTab.slug}/
`
console.log(multibindingsMessage)
return Promise.resolve()
}
export const handler = async (yargs: any) =>
handleCommand(yargs, handlerFn, ["e", "each"])
2 changes: 1 addition & 1 deletion packages/@misk/cli/src/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const handlerFn = async (...args: any) => {
force: false
})
const generator = plop.getGenerator("basic");
generator.runActions({
return generator.runActions({
// This isn't needed (we can title-case a name ourselves), but keeps the command's behaviour the
// same. This should be removed in a future version.
titleCaseName: titleCase,
Expand Down
2 changes: 1 addition & 1 deletion packages/@misk/cli/src/commands/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const handlerFn = async (...args: any) => {
If using ${miskTab.slug} with Misk, make sure to update your multibindings.
Generate new ones with $ miskweb misk`
)
generateMiskTabJson(dir, {
await generateMiskTabJson(dir, {
...miskTab,
relative_path_prefix: `${normalizedPath}/`,
output_path: `lib/web/${normalizedPath}`
Expand Down
2 changes: 1 addition & 1 deletion packages/@misk/cli/src/commands/pin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const handlerFn = async (...args: any) => {
} else {
logDebug("PIN", offlineOrNotFoundMessage("Pin to", pinnedVersion))
}
generateMiskTabJson(dir, {
await generateMiskTabJson(dir, {
...miskTab,
version: versionExistsOnNPM || pinnedVersion
})
Expand Down
4 changes: 2 additions & 2 deletions packages/@misk/cli/src/commands/prebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const command = "prebuild"
export const desc = "use miskTab.json to generate build files\n"
export const handlerFn = async (...args: any) => {
logDebug(command, desc)
migrateBuildFiles(...args)
generateBuildFiles(...args)
await migrateBuildFiles(...args)
await generateBuildFiles(...args)
}
export const handler = async (yargs: any) => handleCommand(yargs, handlerFn)
4 changes: 2 additions & 2 deletions packages/@misk/cli/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export const desc = "start Webpack Dev Server for live editing\n"
export const handlerFn = async (...args: any) => {
logDebug(command, desc)
execute(npmRunScript(command, true), ...args)
return Promise.resolve()
}
export const handler = async (yargs: any) =>
handleCommand(yargs, handlerFn, ["e", "each"])
export const handler = async (yargs: any) => handleCommand(yargs, handlerFn, ["e", "each"])
4 changes: 2 additions & 2 deletions packages/@misk/cli/src/commands/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export const command = "tabs"
export const desc = "prints path of all downstream tabs\n"
export const handlerFn = async (...args: any) => {
execute("pwd", ...args)
return Promise.resolve()
}
export const handler = async (yargs: any) =>
handleCommand({ ...yargs, each: true, hideProgress: true }, handlerFn)
export const handler = async (yargs: any) => handleCommand({ ...yargs, each: true, hideProgress: true }, handlerFn)
1 change: 1 addition & 0 deletions packages/@misk/cli/src/commands/test-coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const desc = "generate test coverage report\n"
export const handlerFn = async (...args: any) => {
logDebug(command, desc)
execute(npmRunScript("test -- --coverage", true), ...args)
return Promise.resolve()
}
export const handler = async (yargs: any) => handleCommand(yargs, handlerFn)
1 change: 1 addition & 0 deletions packages/@misk/cli/src/commands/test-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const desc = "update test snapshots\n"
export const handlerFn = async (...args: any) => {
logDebug(command, desc)
execute(npmRunScript("test -- -u", true), ...args)
return Promise.resolve()
}
export const handler = async (yargs: any) => handleCommand(yargs, handlerFn)
1 change: 1 addition & 0 deletions packages/@misk/cli/src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const desc = "run tests\n"
export const handlerFn = async (...args: any) => {
logDebug(command, desc)
execute(npmRunScript(command, true), ...args)
return Promise.resolve()
}
export const handler = async (yargs: any) => handleCommand(yargs, handlerFn)
4 changes: 2 additions & 2 deletions packages/@misk/cli/src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export const desc = "update Misk Web CLI\n"
export const handlerFn = async (...args: any) => {
logDebug(command, desc, "NPM")
execute("npm install -g @misk/cli", ...args)
return Promise.resolve()
}
export const handler = async (yargs: any) =>
handleCommand(yargs, handlerFn, ["e", "each"])
export const handler = async (yargs: any) => handleCommand(yargs, handlerFn, ["e", "each"])
1 change: 1 addition & 0 deletions packages/@misk/cli/src/commands/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const desc = "zip source code for tab\n"
export const handlerFn = async (...args: any) => {
logDebug(command, desc)
execute(npmRunScript(command), ...args)
return Promise.resolve()
}
export const handler = async (yargs: any) => handleCommand(yargs, handlerFn)
22 changes: 13 additions & 9 deletions packages/@misk/cli/src/utils/handleCommand.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import klaw from "klaw"
import path from "path"
/* eslint-disable-next-line @typescript-eslint/no-var-requires */
const ProgressBar = require("progress")
import { cd } from "shelljs"
import yargs from "yargs"
/* eslint-disable-next-line @typescript-eslint/no-var-requires */
const { version: packageVersion } = require("root-require")("package.json")
import {
packageVersionExistsOnNPM,
Expand Down Expand Up @@ -49,7 +51,7 @@ export const handleCommand = async (
$0: string
hideProgress: boolean
},
handlerFn: (...args: any) => void,
handlerFn: (...args: any) => Promise<void>,
blockedOptions: string[] = []
) => {
// Node version check
Expand All @@ -75,7 +77,7 @@ export const handleCommand = async (
}

// Blocked options (ie. not allowing -e on miskweb start)
let invalidOptions: string[] = []
const invalidOptions: string[] = []
blockedOptions.map((opt: string) => {
if (opt in args) {
invalidOptions.push(opt)
Expand Down Expand Up @@ -115,15 +117,17 @@ export const handleCommand = async (
}
})
.on("error", (err: Error) => console.error(err))
.on("end", async () => {
if (!args.hideProgress) bar.tick(10 - tabs.length)
for (const tab in tabs) {
cd(tabs[tab])
handlerFn({ ...args, dir: tabs[tab] })
}
.on("end", () => {
void (async () => {
if (!args.hideProgress) bar.tick(10 - tabs.length)
for (const tab of tabs) {
cd(tab)
await handlerFn({ ...args, dir: tab })
}
})()
})
} else {
// Execute command in current directory
handlerFn(args)
await handlerFn(args)
}
}
4 changes: 2 additions & 2 deletions packages/@misk/cli/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const parseArgs = (...args: any): { dir: string; rawArgs: any } => ({

export const remove = async (path: string) => {
try {
fs.remove(path)
await fs.remove(path)
} catch (e) {
console.log(`[ERROR] ${e}`)
}
Expand All @@ -93,5 +93,5 @@ export const execute = (cmd: string, ...args: any) => {
}
}

export const npmRunScript = (cmd: string, prebuild: boolean = false) =>
export const npmRunScript = (cmd: string, prebuild = false) =>
`${prebuild ? "miskweb prebuild && " : ""}npm run-script ${cmd}`
24 changes: 12 additions & 12 deletions packages/@misk/cli/src/utils/miskTabUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const tag = "migrate"

const moveOldBuildFile = async (dir: string, filename: Files) => {
if (fs.existsSync(makePath(dir, filename))) {
fs.move(makePath(dir, filename), makePath(dir, Files.old, filename))
await fs.move(makePath(dir, filename), makePath(dir, Files.old, filename))
}
}

Expand Down Expand Up @@ -71,7 +71,7 @@ export const generateMiskTabJson = async (
)
}

export const migrateBuildFiles = (...args: any) => {
export const migrateBuildFiles = async (...args: any) => {
const { dir } = parseArgs(...args)
logDebug(tag, "", dir)
// Verify valid build files or migrate old build files to new miskweb generated build files
Expand Down Expand Up @@ -110,22 +110,22 @@ export const migrateBuildFiles = (...args: any) => {
)
} else if (!pkgMiskTab && fs.existsSync(makePath(dir, Files.miskTab))) {
// miskTab.json exists. Rewrite out with alphabetically sorted and up to date set of keys.
generateMiskTabJson(dir)
await generateMiskTabJson(dir)
} else if (pkgMiskTab && !fs.existsSync(makePath(dir, Files.miskTab))) {
generateMiskTabJson(dir, pkgMiskTab)
await generateMiskTabJson(dir, pkgMiskTab)
// move all build files to an .old-build-files folder
logDebug(tag, `Stashing old build files in ${makePath(dir, Files.old)}`)
fs.mkdirp(makePath(dir, Files.old))
fs.copy(
await fs.mkdirp(makePath(dir, Files.old))
await fs.copy(
makePath(dir, Files.package),
makePath(dir, Files.old, Files.package)
)
moveOldBuildFile(dir, Files.gitignore)
moveOldBuildFile(dir, Files.prettier)
moveOldBuildFile(dir, Files.tsconfig)
moveOldBuildFile(dir, Files.webpack)
remove(makePath(dir, Files.packageLock))
remove(makePath(dir, Files.yarnLock))
await moveOldBuildFile(dir, Files.gitignore)
await moveOldBuildFile(dir, Files.prettier)
await moveOldBuildFile(dir, Files.tsconfig)
await moveOldBuildFile(dir, Files.webpack)
await remove(makePath(dir, Files.packageLock))
await remove(makePath(dir, Files.yarnLock))
} else if (!pkgMiskTab && !fs.existsSync(makePath(dir, Files.miskTab))) {
throw Error(
logFormatter(
Expand Down
5 changes: 3 additions & 2 deletions packages/@misk/cli/src/utils/resolveNpmVersion.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import axios from "axios"
import { chain, isNaN, isNumber } from "lodash"
const { version: packageVersion } = require("root-require")("package.json")
/* eslint-disable-next-line @typescript-eslint/no-var-requires */
const { version: packageVersion } = require("root-require")("package.json")
import { MiskPkg, logDebug } from "../utils"

export const offlineOrNotFoundMessage = (
verb: string,
version: string,
fromLocation: string = ""
fromLocation = ""
) =>
`\n[WARN] ${verb} unconfirmed Misk Web @ ${version} ${fromLocation}.\nmiskweb is offline or cannot find v(${version}) published on NPM.`

Expand Down
8 changes: 4 additions & 4 deletions packages/@misk/cli/tests/utils/resolveNpmVersion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const NPM_LATEST = "0.1.9"
const LOCAL_CLI_PACKAGE_VERSION = "0.1.5"

describe("Test versionResolver logic to ensure SemVar version always returned", () => {
it("Online valid SemVar version returns itself", async () => {
it("Online valid SemVar version returns itself", () => {
expect(
versionResolver(
MISK_TAB_VERSION,
Expand All @@ -15,12 +15,12 @@ describe("Test versionResolver logic to ensure SemVar version always returned",
)
).toBe(MISK_TAB_VERSION)
})
it("Online version set as latest resolves to online SemVar version", async () => {
it("Online version set as latest resolves to online SemVar version", () => {
expect(
versionResolver(MISK_TAB_LATEST, NPM_LATEST, LOCAL_CLI_PACKAGE_VERSION)
).toBe(NPM_LATEST)
})
it("Offline SemVar version returns itself", async () => {
it("Offline SemVar version returns itself", () => {
expect(
versionResolver(
MISK_TAB_VERSION,
Expand All @@ -29,7 +29,7 @@ describe("Test versionResolver logic to ensure SemVar version always returned",
)
).toBe(MISK_TAB_VERSION)
})
it("Offline latest version returns CLI version", async () => {
it("Offline latest version returns CLI version", () => {
expect(
versionResolver(
MISK_TAB_LATEST,
Expand Down
3 changes: 2 additions & 1 deletion packages/@misk/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"dev": "npm run-script build; npm run-script updateDevCache",
"ci-build": "npm run-script clean && npm run-script lib",
"lib": "npm run-script refresh; webpack --config webpack.config.js && webpack --config webpack.config.static.js && webpack --config webpack.config.vendors.js",
"lint": "prettier --write --config package.json .",
"lint": "prettier --write --config package.json . && npm run eslint",
"eslint": "eslint .",
"gradle": "cd ../../../../../ && ./gradlew web -Pcmd='-ca' -Ptabs='@misk/common'",
"prepare": "npm run-script ci-build",
"refresh": "node refreshCachedUrls.js",
Expand Down
3 changes: 2 additions & 1 deletion packages/@misk/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"dev": "npm run-script build; npm run-script updateDevCache",
"ci-build": "npm run-script clean && npm run-script lib",
"lib": "webpack",
"lint": "prettier --write --config package.json .",
"lint": "prettier --write --config package.json . && npm run eslint",
"eslint": "eslint .",
"gradle": "cd ../../../../../ && ./gradlew web -Pcmd='-ca' -Ptabs='@misk/core'",
"prepare": "npm run-script ci-build",
"reinstall": "rm -rf node_modules && npm install",
Expand Down
Loading

0 comments on commit e1a5eb4

Please sign in to comment.