Skip to content

Commit

Permalink
Merge pull request #1442 from intuit/unresolved-deps
Browse files Browse the repository at this point in the history
upgrade eslint + ensure all imported packages are in package.json
  • Loading branch information
hipstersmoothie authored Aug 6, 2020
2 parents 34d34f5 + 5d5edcb commit 130a7a8
Show file tree
Hide file tree
Showing 42 changed files with 303 additions and 154 deletions.
10 changes: 9 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@
"xo",
"plugin:jest/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"prettier",
"prettier/@typescript-eslint"
],

"plugins": ["prettier", "jest", "@typescript-eslint", "eslint-plugin-jsdoc"],
"plugins": ["prettier", "jest", "@typescript-eslint", "eslint-plugin-jsdoc", "import"],

"rules": {
"import/no-extraneous-dependencies": 2,
/* xo config */

// makes commenting out lines quickly a hassle
"capitalized-comments": 0,
"camelcase": 0,
"default-param-last": 0,
"complexity": ["error", { "max": 25 }],

Expand All @@ -39,6 +44,8 @@
/* typescript */

"no-undef": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/no-unnecessary-type-arguments": 2,
"@typescript-eslint/no-unnecessary-type-assertion": 2,
"@typescript-eslint/no-unnecessary-boolean-literal-compare": 2,
Expand Down Expand Up @@ -89,6 +96,7 @@
{
"files": ["*.test.*"],
"rules": {
"import/namespace": 0,
"no-import-assign": 0,
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-non-null-assertion": 0,
Expand Down
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@
"@fortawesome/react-fontawesome": "^0.1.9",
"@types/jest": "^26.0.0",
"@types/parse-github-url": "1.0.0",
"@typescript-eslint/eslint-plugin": "^2.7.0",
"@typescript-eslint/parser": "^2.7.0",
"@typescript-eslint/eslint-plugin": "^3.8.0",
"@typescript-eslint/parser": "^3.8.0",
"all-contributors-cli": "^6.4.0",
"change-case": "^4.0.0",
"command-line-docs": "^0.0.6",
"copy-template-dir": "^1.4.0",
"endent": "^2.0.1",
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.4.0",
"eslint-config-xo": "^0.29.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^23.0.1",
"eslint-plugin-jsdoc": "^30.0.2",
"eslint-plugin-prettier": "^3.1.1",
"eslint": "^7.6.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-xo": "^0.32.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^23.20.0",
"eslint-plugin-jsdoc": "^30.2.1",
"eslint-plugin-prettier": "^3.1.4",
"graphql": "^15.0.0",
"husky": "^4.0.7",
"ignite": "1.11.2",
Expand All @@ -74,7 +74,6 @@
"simple-react-lightbox": "^3.1.2-3",
"title-case": "^3.0.2",
"ts-jest": "^26.1.3",
"type-fest": "^0.16.0",
"typescript": "~3.9.3"
},
"husky": {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/__tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import main, { run } from "../src/run";
import { runCli, execute } from "../src/run";

process.env.GH_TOKEN = "XXXX";

Expand All @@ -9,7 +9,7 @@ test("throws error for unknown args", async () => {
console.log = jest.fn() as any;

// @ts-ignore
await run("foo", { foo: 123 });
await execute("foo", { foo: 123 });

expect(process.exit).toHaveBeenCalledWith(1);
});
Expand All @@ -18,7 +18,7 @@ test("throws exits for caught error", async () => {
console.log = jest.fn() as any;
process.exit = jest.fn() as any;

await main("foo", {});
await runCli("foo", {});

expect(process.exit).toHaveBeenCalledWith(1);
});
4 changes: 2 additions & 2 deletions packages/cli/src/bin/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ try {

import chalk from "chalk";
import parseArgs from "../parse-args";
import run from "../run";
import { runCli } from "../run";

const [command, args] = parseArgs();

if (command && args) {
run(command, args).catch((e: Error) => {
runCli(command, args).catch((e: Error) => {
console.error(chalk.redBright("Error: "), e.message);
process.exit(1);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/parse-args.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getAutoVersion } from "@auto-it/core";
import chalk from "chalk";
import { app, Command, Option } from "command-line-application";
import endent from "endent";
Expand All @@ -17,6 +16,7 @@ import {
IReleaseOptions,
IShipItOptions,
IVersionOptions,
getAutoVersion,
} from "@auto-it/core";

export type Flags =
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import on from "await-to-js";
import link from "terminal-link";

/** Spin up the "auto" node API and provide it the parsed CLI args. */
export async function run(command: string, args: ApiOptions) {
export async function execute(command: string, args: ApiOptions) {
const auto = new Auto(args);

try {
Expand Down Expand Up @@ -140,6 +140,6 @@ export async function run(command: string, args: ApiOptions) {
}

/** Run "auto" for a given command. */
export default async function main(command: string, args: ApiOptions) {
await run(command, args);
export async function runCli(command: string, args: ApiOptions) {
await execute(command, args);
}
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"terminal-link": "^2.1.1",
"tinycolor2": "^1.4.1",
"tslib": "2.0.0",
"type-fest": "^0.16.0",
"typescript-memoize": "^1.0.0-alpha.3",
"url-join": "^4.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/auto-canary-local.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Auto from "../auto";
import { Auto } from "../auto";
import SEMVER from "../semver";
import { dummyLog } from "../utils/logger";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/auto-comment.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Auto from "../auto";
import { Auto } from "../auto";
import { dummyLog } from "../utils/logger";

jest.mock("env-ci", () => () => ({ pr: 123 }));
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/auto-env.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Auto from "../auto";
import { Auto } from "../auto";

jest.mock("fs", () => ({
readFileSync: () => 'FOO="test value"',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/auto-git-user-in-ci.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Auto from "../auto";
import { Auto } from "../auto";
import execPromise from "../utils/exec-promise";

const exec = jest.fn();
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/auto-in-pr-ci.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Auto from "../auto";
import { Auto } from "../auto";
import SEMVER from "../semver";
import { dummyLog } from "../utils/logger";
import makeCommitFromMsg from "./make-commit-from-msg";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/auto-make-changelog.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Auto from "../auto";
import { Auto } from "../auto";
import { dummyLog } from "../utils/logger";
import child from "child_process";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/auto.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Auto from "../auto";
import { Auto } from "../auto";
import { IPRStatusOptions } from "../auto-args";
import SEMVER from "../semver";
import { dummyLog } from "../utils/logger";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/get-remote.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Auto from "../auto";
import { Auto } from "../auto";

jest.mock("child_process");

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/major-version-branches.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Auto from "../auto";
import { Auto } from "../auto";
import SEMVER from "../semver";
import execPromise from "../utils/exec-promise";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/remote.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Auto from "../auto";
import { Auto } from "../auto";
import { dummyLog } from "../utils/logger";

const defaultRemote = "[email protected]";
Expand Down
16 changes: 11 additions & 5 deletions packages/core/src/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ import {
ILatestOptions,
} from "./auto-args";
import Changelog from "./changelog";
import { preVersionMap } from "./semver";
import Config from "./config";
import Config, { DEFAULT_PRERELEASE_BRANCHES } from "./config";
import Git, { IGitOptions, IPRInfo } from "./git";
import InteractiveInit from "./init";
import LogParse, { IExtendedCommit } from "./log-parse";
Expand All @@ -48,6 +47,7 @@ import SEMVER, {
calculateSemVerBump,
IVersionLabels,
ILabelDefinition,
preVersionMap,
} from "./semver";
import execPromise from "./utils/exec-promise";
import { loadPlugin, IPlugin, listPlugins } from "./utils/load-plugins";
Expand Down Expand Up @@ -635,7 +635,10 @@ export default class Auto {
const [, gitVersion = ""] = await on(execPromise("git", ["--version"]));
const [noProject, project] = await on(this.git.getProject());
const repo = (await this.getRepo(this.config!)) || {};
const repoLink = link(`${repo.owner}/${repo.repo}`, project?.html_url!);
const repoLink = link(
`${repo.owner}/${repo.repo}`,
project?.html_url ?? ""
);
const author = (await this.getGitUser()) || ({} as IAuthor);
const [, lastRelease = "0.0.0"] = await on(this.git.getLatestRelease());
const version = await this.getCurrentVersion(lastRelease);
Expand Down Expand Up @@ -727,7 +730,8 @@ export default class Auto {
/** Determine if the repo is currently in a prerelease branch */
inPrereleaseBranch(): boolean {
const branch = getCurrentBranch();
const prereleaseBranches = this.config?.prereleaseBranches!;
const prereleaseBranches =
this.config?.prereleaseBranches ?? DEFAULT_PRERELEASE_BRANCHES;

return Boolean(branch && prereleaseBranches.includes(branch));
}
Expand Down Expand Up @@ -1304,7 +1308,8 @@ export default class Auto {
const current = await this.getCurrentVersion(lastRelease);

if (parse(current)) {
const prereleaseBranches = this.config?.prereleaseBranches!;
const prereleaseBranches =
this.config?.prereleaseBranches ?? DEFAULT_PRERELEASE_BRANCHES;
const branch = getCurrentBranch() || "";
const prereleaseBranch = prereleaseBranches.includes(branch)
? branch
Expand Down Expand Up @@ -2115,6 +2120,7 @@ export default class Auto {

export * from "./auto-args";
export { default as InteractiveInit } from "./init";
export { DEFAULT_PRERELEASE_BRANCHES } from "./config";
export { getCurrentBranch } from "./utils/get-current-branch";
export { validatePluginConfiguration } from "./validate-config";
export { ILogger } from "./utils/logger";
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import join from "url-join";
import botList from "@auto-it/bot-list";

import { ICommitAuthor, IExtendedCommit } from "./log-parse";
import { ILabelDefinition } from "./semver";
import SEMVER, { ILabelDefinition } from "./semver";
import { ILogger } from "./utils/logger";
import { makeChangelogHooks } from "./utils/make-hooks";
import { getCurrentBranch } from "./utils/get-current-branch";
import SEMVER from "./semver";
import { automatedCommentIdentifier } from "./git";

export interface IGenerateReleaseNotesOptions {
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import tryRequire from "./utils/try-require";
import endent from "endent";
import { ILabelDefinition, defaultLabels } from "./semver";

export const DEFAULT_PRERELEASE_BRANCHES = ["next"];

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type ConfigObject = any;

Expand Down Expand Up @@ -89,7 +91,7 @@ export default class Config {
return {
...rawConfig,
labels,
prereleaseBranches: rawConfig.prereleaseBranches || ["next"],
prereleaseBranches: rawConfig.prereleaseBranches || DEFAULT_PRERELEASE_BRANCHES,
versionBranches:
typeof rawConfig.versionBranches === "boolean" &&
rawConfig.versionBranches
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface IGitOptions {
/** An error originating from the GitHub */
class GitAPIError extends Error {
/** Extend the base error */
constructor(api: string, args: object, origError: Error) {
constructor(api: string, args: Record<string, unknown> | unknown[], origError: Error) {
super(
`Error calling github: ${api}\n\twith: ${JSON.stringify(args)}.\n\t${
origError.message
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-await-in-loop, @typescript-eslint/ban-ts-ignore */
/* eslint-disable no-await-in-loop */

import endent from "endent";
import { prompt } from "enquirer";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import makeCommitFromMsg from "../../__tests__/make-commit-from-msg";
import Auto from "../../auto";
import { Auto } from "../../auto";
import Git from "../../git";
import LogParse from "../../log-parse";
import { makeHooks, makeLogParseHooks } from "../../utils/make-hooks";
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
ISearchQuery,
} from "./match-sha-to-pr";
import { LoadedAutoRc } from "./types";
import { DEFAULT_PRERELEASE_BRANCHES } from "./config";

/** Construct a map of label => semver label */
export const getVersionMap = (labels = defaultLabels) =>
Expand Down Expand Up @@ -74,7 +75,7 @@ export default class Release {
git: Git,
config: LoadedAutoRc = {
baseBranch: "master",
prereleaseBranches: ["next"],
prereleaseBranches: DEFAULT_PRERELEASE_BRANCHES,
labels: defaultLabels,
},
logger: ILogger = dummyLog()
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/utils/__tests__/test-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
interface TestOptions {
/** Test property */
foo: string;
}

module.exports = class Test {
/** The name of the plugin */
name = "foo";

/** The options of the plugin */
config: {};
config: TestOptions;

/** Initialize the plugin with it's options */
constructor(config: {}) {
constructor(config: TestOptions) {
this.config = config;
}
};
2 changes: 1 addition & 1 deletion packages/core/src/utils/load-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import endent from "endent";
import glob from "fast-glob";

import * as path from "path";
import Auto from "../auto";
import { Auto } from "../auto";
import { ILogger } from "./logger";
import tryRequire from "./try-require";
import InteractiveInit from "../init";
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/ban-ts-ignore */

import signale from "signale";

export type LogLevel = undefined | "verbose" | "veryVerbose" | "quiet";
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/utils/try-require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export default function tryRequire(tryPath: string, from?: string) {
try {
// Require from __dirname. Needed for npx and global installs
return require(tryPath);
} catch (error) {}
} catch (error) {
logger.veryVerbose.warn(error.message);
}

if (from) {
try {
Expand Down
Loading

0 comments on commit 130a7a8

Please sign in to comment.