Skip to content

Commit

Permalink
test: 馃毃 fixed linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 18, 2021
1 parent fc8b67c commit b357026
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
19 changes: 6 additions & 13 deletions __tests__/config.ts
Expand Up @@ -9,38 +9,31 @@ test("load config", async () => {

test("missing prop code", () => {
expect(() => {
const config = ({ devmoji: [{ foo: 1 }] } as unknown) as ConfigOptions
const config = { devmoji: [{ foo: 1 }] } as unknown as ConfigOptions
new Config(config)
}).toThrow(/code is missing/)
})

test("missing prop emoji", () => {
expect(() => {
const config = ({
const config = {
devmoji: [{ code: "foo" }],
} as unknown) as ConfigOptions
} as unknown as ConfigOptions
new Config(config)
}).toThrow(/Missing.*emoji.*/)
})

test("missing config file", () => {
expect.assertions(1)
return Config.load("missing-config-file").catch((error) =>
expect(error).toMatch(/missing.*/)
)
})

test("config without devmoji", () => {
const config = ({ types: [] } as unknown) as ConfigOptions
const config = { types: [] } as unknown as ConfigOptions
expect(() => {
new Config(config)
}).not.toThrow()
})

test("invalid gitmoji", () => {
const config = ({
const config = {
devmoji: [{ code: "test", gitmoji: "foobar" }],
} as unknown) as ConfigOptions
} as unknown as ConfigOptions
expect(() => {
new Config(config)
}).toThrow(/Gitmoji .* not found/)
Expand Down
7 changes: 4 additions & 3 deletions src/cli.ts
Expand Up @@ -23,9 +23,10 @@ export class Cli {
if (/^([rR]evert)/.test(text)) return []

const errors = []
const match = /^(?<type>:?[a-z-]+)(?:\((?<scope>[a-z-0-9]+)\))?(!?):\s+(?<description>.*)/iu.exec(
text
)
const match =
/^(?<type>:?[a-z-]+)(?:\((?<scope>[a-z-0-9]+)\))?(!?):\s+(?<description>.*)/iu.exec(
text
)
if (match) {
const type = match.groups?.type ?? ""
const description = match.groups?.description
Expand Down
4 changes: 3 additions & 1 deletion src/conventional-commits.ts
Expand Up @@ -2,7 +2,9 @@ import { Devmoji } from "./devmoji"
import chalk from "chalk"

export class ConventionalCommits {
regex = /(?<type>:?[a-z-]+)(?:\((?<scope>[a-z-0-9]+)\))?(!?):\s*(?:(?<other>(?::[a-z-]+:\s*)+)\s*)?/gimu
regex =
/(?<type>:?[a-z-]+)(?:\((?<scope>[a-z-0-9]+)\))?(!?):\s*(?:(?<other>(?::[a-z-]+:\s*)+)\s*)?/gimu

constructor(public devmoji: Devmoji) {}

formatCommit(text: string, color = false) {
Expand Down
3 changes: 2 additions & 1 deletion src/devmoji.ts
Expand Up @@ -4,7 +4,8 @@ import { github, gitmoji } from "./emoji-pack"
export class Devmoji {
shortcodeRegex = /:([a-zA-Z0-9_\-+]+):/g
shortcodeSpaceRegex = /\s?:([a-zA-Z0-9_\-+]+):/g
unicodeRegex = /((?:\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])\ufe0f?)/g
unicodeRegex =
/((?:\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])\ufe0f?)/g

constructor(public config: Config) {}

Expand Down
4 changes: 2 additions & 2 deletions src/scripts/updater.ts
Expand Up @@ -41,7 +41,7 @@ export async function update() {
})

fetch("https://api.github.com/emojis", { method: "GET" })
.then((res) => (res.json() as unknown) as Record<string, string>)
.then((res) => res.json() as unknown as Record<string, string>)
.then((json) => {
const regex = /unicode\/(.*)\.png.*/
let added = 0
Expand Down Expand Up @@ -90,7 +90,7 @@ export async function update() {
{ method: "GET" }
)
.then(
(res) => (res.json() as unknown) as { gitmojis: Record<string, unknown> }
(res) => res.json() as unknown as { gitmojis: Record<string, unknown> }
)
.then((json) => {
fs.writeFileSync(
Expand Down

0 comments on commit b357026

Please sign in to comment.