Skip to content

Commit

Permalink
style: 馃帹 fixed linting errors for all src and __tests__ source files
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Nov 30, 2020
1 parent 48596c4 commit 2a93269
Show file tree
Hide file tree
Showing 12 changed files with 1,876 additions and 6,355 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -13,6 +13,7 @@ module.exports = {
"prettier",
"prettier/@typescript-eslint",
],
reportUnusedDisableDirectives: true,
env: {
node: true,
browser: false,
Expand Down
12 changes: 6 additions & 6 deletions __tests__/cli-tester.ts
Expand Up @@ -24,22 +24,22 @@ test("sync2", () => {
expect(mockCli.stdout?.data).toMatch(/test/)
})

test("async1", () => {
test("async1", async () => {
const mockCli = new MockCli()
mockCli.testAsync(async () => {
await new Promise((done) => {
await mockCli.testAsync(async () => {
await new Promise<void>((done) => {
process.stdout.write("test")
done()
})
})
expect(mockCli.stdout?.data).toMatch(/test/)
})

test("async2", () => {
test("async2", async () => {
const mockCli = new MockCli()
mockCli.testAsync(async () => {
await mockCli.testAsync(async () => {
console.log("foo")
await new Promise((done) => {
await new Promise<void>((done) => {
console.log("test")
done()
})
Expand Down
32 changes: 12 additions & 20 deletions __tests__/config.ts
Expand Up @@ -9,46 +9,38 @@ test("load config", async () => {

test("missing prop code", () => {
expect(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const config: ConfigOptions = { devmoji: [{ foo: 1 }] } as any
const config = ({ devmoji: [{ foo: 1 }] } as unknown) as ConfigOptions
new Config(config)
}).toThrow(/code is missing/)
})

test("missing prop emoji", () => {
expect(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const config: ConfigOptions = {
const config = ({
devmoji: [{ code: "foo" }],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any
} as unknown) as ConfigOptions
new Config(config)
}).toThrow(/Missing.*emoji.*/)
})

test("missing config file", async () => {
try {
await Config.load("missing-config-file")
} catch (error) {
// eslint-disable-next-line jest/no-try-expect
test("missing config file", () => {
expect.assertions(1)
return Config.load("missing-config-file").catch((error) =>
expect(error).toMatch(/missing.*/)
}
)
})

test("config without devmoji", () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const config: ConfigOptions = { types: [] } as any
const config = ({ types: [] } as unknown) as ConfigOptions
expect(() => {
new Config(config)
}).not.toThrow()
})

test("invalid gitmoji", () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const config: ConfigOptions = {
const config = ({
devmoji: [{ code: "test", gitmoji: "foobar" }],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any
} as unknown) as ConfigOptions
expect(() => {
new Config(config)
}).toThrow(/Gitmoji .* not found/)
Expand All @@ -58,7 +50,7 @@ test("default config file", async () => {
try {
await Config.load()
} catch (error) {
// eslint-disable-next-line jest/no-try-expect
// eslint-disable-next-line jest/no-try-expect, jest/no-conditional-expect
expect(error).toMatch(/missing.*/)
}
})
Expand All @@ -67,7 +59,7 @@ test("no default config file", async () => {
try {
await Config.load(undefined, "/")
} catch (error) {
// eslint-disable-next-line jest/no-try-expect
// eslint-disable-next-line jest/no-try-expect, jest/no-conditional-expect
expect(error).toMatch(/missing.*/)
}
})
7 changes: 3 additions & 4 deletions __tests__/emoji-pack.ts
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import gitmojis from "../src/data/gitmoji.emoji"
import { github, gitmoji } from "../src/emoji-pack"

Expand All @@ -11,10 +12,8 @@ test("all gitmoji should be valid", () => {
expect(github.get(shortcode)?.emoji).toBeDefined()
const em = github.get(shortcode)
expect(em).toBeDefined()
if (em) {
expect(em.emoji).toBeDefined()
expect(github.getCode(em.emoji)).toBeDefined()
}
expect(em!.emoji).toBeDefined()
expect(github.getCode(em!.emoji)).toBeDefined()
}
})

Expand Down
2 changes: 1 addition & 1 deletion __tests__/lint.ts
@@ -1,6 +1,6 @@
import { Cli } from "../src/cli"

test("should ", async () => {
test("should", async () => {
const cli = await Cli.create(["", ""], true)
const valid = `style: 馃帹 prettier 2.0
Merge branch 'master' of github.com:folke/devmoji
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -44,7 +44,7 @@
"test": "npx jest",
"test:cov": "npx jest --coverage",
"lint": "yarn lint:eslint && yarn lint:ts",
"lint:eslint": "npx eslint src/*.ts --cache --fix",
"lint:eslint": "npx eslint src/**/*.ts __tests__/**/*.ts --cache --fix",
"lint:ts": "npx tsc -p tsconfig.build.json --noEmit",
"prepack": "yarn build",
"release": "source .env && npx semantic-release --color --no-ci"
Expand Down
3 changes: 0 additions & 3 deletions src/cli-tester.ts
Expand Up @@ -27,21 +27,18 @@ export class MockCli {
stdout?: StringWritable
stderr?: StringWritable
console = global.console
// eslint-disable-next-line @typescript-eslint/unbound-method

mock(stream: Writable) {
const mock = new StringWritable()
// eslint-disable-next-line @typescript-eslint/unbound-method
this.mocks.push([mock, stream, stream.write])
// eslint-disable-next-line @typescript-eslint/unbound-method
stream.write = mock.write.bind(mock)
return mock
}

restore() {
for (const [mock, stream, write] of this.mocks) {
mock.destroy()
// eslint-disable-next-line @typescript-eslint/unbound-method
stream.write = write.bind(stream)
}
global.console = this.console
Expand Down
5 changes: 3 additions & 2 deletions src/cli.ts
Expand Up @@ -40,8 +40,9 @@ export class Cli {
} else {
errors.push(`Expecting a commit message like:`)
errors.push(
` ${chalk.blue("type" + chalk.bold("(scope):")) +
chalk.dim(" description")
` ${
chalk.blue("type" + chalk.bold("(scope):")) +
chalk.dim(" description")
}`
)
}
Expand Down

0 comments on commit 2a93269

Please sign in to comment.