Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies, replace husky with vscode, run prettier #337

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "all"
}
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"files.exclude": {
"**/.dist": true
}
}
9,128 changes: 1,770 additions & 7,358 deletions package-lock.json

Large diffs are not rendered by default.

27 changes: 12 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"lint": "eslint . --ext .js,.ts",
"pretest": "npm run lint",
"test": "jest",
"pretty-quick": "pretty-quick",
"write-docs": "tsc && node dist/docs.js",
"build": "tsc",
"prepublishOnly": "pinst --disable && tsc",
Expand All @@ -26,24 +25,22 @@
},
"homepage": "https://github.com/double-great/alt-text#readme",
"dependencies": {
"emoji-regex": "^10.2.1",
"emoji-regex": "^10.3.0",
"github-slugger": "^2.0.0"
},
"devDependencies": {
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.21.0",
"@types/jest": "^29.4.0",
"@types/node": "^18.14.4",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
"husky": "^8.0.3",
"jest": "^29.4.3",
"@babel/preset-env": "^7.23.5",
"@babel/preset-typescript": "^7.23.3",
"@types/jest": "^29.5.10",
"@types/node": "^20.10.3",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.1.0",
"jest": "^29.7.0",
"pinst": "^3.0.0",
"prettier": "^2.8.4",
"pretty-quick": "^3.1.3",
"typescript": "^4.9.5"
"prettier": "^3.1.0",
"typescript": "^5.3.2"
},
"directories": {
"test": "tests"
Expand Down
36 changes: 18 additions & 18 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ describe("altText", () => {
expect(altText("A large black dog.")).toBeUndefined();
expect(altText("A child holding a photograph.")).toBeUndefined();
expect(
altText("An inhaler with a spacer connected to the mouthpiece.")
altText("An inhaler with a spacer connected to the mouthpiece."),
).toBeUndefined();
});

test("empty", () => {
expect(altText()).toMatchInlineSnapshot(
`"Empty alt text should only be used for decorative images (https://doublegreat.dev/alt-text/#image-is-decorative)."`
`"Empty alt text should only be used for decorative images (https://doublegreat.dev/alt-text/#image-is-decorative)."`,
);
expect(altText("")).toMatchInlineSnapshot(
`"Empty alt text should only be used for decorative images (https://doublegreat.dev/alt-text/#image-is-decorative)."`
`"Empty alt text should only be used for decorative images (https://doublegreat.dev/alt-text/#image-is-decorative)."`,
);
});

Expand All @@ -24,69 +24,69 @@ describe("altText", () => {

test("return suggestions", () => {
expect(altText("A SCREENSHOT OF A DOG.")).toMatchInlineSnapshot(
`"Alt text should not contain "screenshot of" (https://doublegreat.dev/alt-text/#alt-text-contains-unhelpful-words)."`
`"Alt text should not contain "screenshot of" (https://doublegreat.dev/alt-text/#alt-text-contains-unhelpful-words)."`,
);
expect(altText("A SCREENSHOT OF A DOG")).toMatchInlineSnapshot(
`"Alt text should not contain "screenshot of" (https://doublegreat.dev/alt-text/#alt-text-contains-unhelpful-words). Alt text should end with punctuation (https://doublegreat.dev/alt-text/#end-with-punctuation)."`
`"Alt text should not contain "screenshot of" (https://doublegreat.dev/alt-text/#alt-text-contains-unhelpful-words). Alt text should end with punctuation (https://doublegreat.dev/alt-text/#end-with-punctuation)."`,
);
expect(
altText("An inhaler with a spacer connected to the mouthpiece")
altText("An inhaler with a spacer connected to the mouthpiece"),
).toMatchInlineSnapshot(
`"Alt text should end with punctuation (https://doublegreat.dev/alt-text/#end-with-punctuation)."`
`"Alt text should end with punctuation (https://doublegreat.dev/alt-text/#end-with-punctuation)."`,
);
expect(altText("😸.")).toMatchInlineSnapshot(
`"Replace 😸 in alt text with descriptive text (https://doublegreat.dev/alt-text/#avoid-emoji)."`
`"Replace 😸 in alt text with descriptive text (https://doublegreat.dev/alt-text/#avoid-emoji)."`,
);
});

test("config, disabled", () => {
expect(
altText("An orange 🐈.", { "avoid-emoji": false })
altText("An orange 🐈.", { "avoid-emoji": false }),
).toMatchInlineSnapshot(`undefined`);

expect(
altText(
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
{ "character-length": false }
)
{ "character-length": false },
),
).toMatchInlineSnapshot(`undefined`);

expect(
altText("A screenshot of a dog.", {
"contains-unhelpful-word": false,
})
}),
).toMatchInlineSnapshot(`undefined`);

expect(
altText("An orange cat", { "end-with-punctuation": false })
altText("An orange cat", { "end-with-punctuation": false }),
).toMatchInlineSnapshot(`undefined`);

expect(
altText("An orange cat.jpg", {
"should-not-end-with": false,
"end-with-punctuation": false,
})
}),
).toMatchInlineSnapshot(`undefined`);

expect(
altText("Photograph: an orange cat.", {
"should-not-start-with": false,
})
}),
).toMatchInlineSnapshot(`undefined`);

expect(altText(" ", { "empty-alt-text": false })).toMatchInlineSnapshot(
`undefined`
`undefined`,
);

expect(altText("icon", { "is-unhelpful": false })).toMatchInlineSnapshot(
`"Alt text should end with punctuation (https://doublegreat.dev/alt-text/#end-with-punctuation)."`
`"Alt text should end with punctuation (https://doublegreat.dev/alt-text/#end-with-punctuation)."`,
);

expect(
altText("icon", {
"is-unhelpful": false,
"end-with-punctuation": false,
})
}),
).toMatchInlineSnapshot(`undefined`);
});
});
2 changes: 1 addition & 1 deletion src/clues/__tests__/avoid-emoji.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("avoidEmoji", () => {
it("`docs` matches generated GitHub `heading` link", async () => {
expect.assertions(1);
await expect(checkDocsLink(avoidEmoji.heading)).resolves.toEqual(
avoidEmoji.docs
avoidEmoji.docs,
);
});
});
8 changes: 4 additions & 4 deletions src/clues/__tests__/char-length.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ describe("charLength", () => {
it("check", () => {
expect(
charLength.check(
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
)
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
),
).toMatchInlineSnapshot(`
[
"Alt text length should be less than 125 characters, it is currently 446 characters (https://doublegreat.dev/alt-text/#character-length).",
]
`);
expect(
charLength.check("Lorem ipsum dolor sit amet")
charLength.check("Lorem ipsum dolor sit amet"),
).toMatchInlineSnapshot(`[]`);
expect(charLength.check("Lorem ipsum dolor sit amet", { length: 10 }))
.toMatchInlineSnapshot(`
Expand All @@ -54,7 +54,7 @@ describe("charLength", () => {
it("`docs` matches generated GitHub `heading` link", async () => {
expect.assertions(1);
await expect(checkDocsLink(charLength.heading)).resolves.toEqual(
charLength.docs
charLength.docs,
);
});
});
4 changes: 2 additions & 2 deletions src/clues/__tests__/contains.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("altContains", () => {
expect(
altContains.check("A photo of a large black dog illustration.", {
exclude: ["illustration"],
})
}),
).toMatchInlineSnapshot(`
[
"Alt text should not contain "illustration" (https://doublegreat.dev/alt-text/#alt-text-contains-unhelpful-words).",
Expand All @@ -50,7 +50,7 @@ describe("altContains", () => {
it("`docs` matches generated GitHub `heading` link", async () => {
expect.assertions(1);
await expect(checkDocsLink(altContains.heading)).resolves.toEqual(
altContains.docs
altContains.docs,
);
});
});
4 changes: 2 additions & 2 deletions src/clues/__tests__/decorative.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ describe("decorative", () => {
});
it("check", () => {
expect(decorative.check()).toMatchInlineSnapshot(
`"Empty alt text should only be used for decorative images (https://doublegreat.dev/alt-text/#image-is-decorative)."`
`"Empty alt text should only be used for decorative images (https://doublegreat.dev/alt-text/#image-is-decorative)."`,
);
});
it("`docs` matches generated GitHub `heading` link", async () => {
expect.assertions(1);
await expect(checkDocsLink(decorative.heading)).resolves.toEqual(
decorative.docs
decorative.docs,
);
});
});
4 changes: 2 additions & 2 deletions src/clues/__tests__/end-punctuation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ describe("endPunctuation", () => {
]
`);
expect(endPunctuation.check("A large block dog?")).toMatchInlineSnapshot(
`[]`
`[]`,
);
});
it("`docs` matches generated GitHub `heading` link", async () => {
expect.assertions(1);
await expect(checkDocsLink(endPunctuation.heading)).resolves.toEqual(
endPunctuation.docs
endPunctuation.docs,
);
});
});
4 changes: 2 additions & 2 deletions src/clues/__tests__/end-with.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("altEndsWith", () => {
expect(
altEndsWith.check("DSC_0010.gov", {
exclude: [".gov"],
})
}),
).toMatchInlineSnapshot(`
[
"Alt text should not end with ".gov" (https://doublegreat.dev/alt-text/#alt-text-should-not-end-with).",
Expand All @@ -60,7 +60,7 @@ describe("altEndsWith", () => {
it("`docs` matches generated GitHub `heading` link", async () => {
expect.assertions(1);
await expect(checkDocsLink(altEndsWith.heading)).resolves.toEqual(
altEndsWith.docs
altEndsWith.docs,
);
});
});
2 changes: 1 addition & 1 deletion src/clues/__tests__/exact-match.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("exactMatch", () => {
it("`docs` matches generated GitHub `heading` link", async () => {
expect.assertions(1);
await expect(checkDocsLink(exactMatch.heading)).resolves.toEqual(
exactMatch.docs
exactMatch.docs,
);
});
});
4 changes: 2 additions & 2 deletions src/clues/__tests__/image-link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ describe("imageLink", () => {
});
it("check", () => {
expect(imageLink.check()).toMatchInlineSnapshot(
`"Images inside a link tag require alt text that describes the purpose of the link (https://doublegreat.dev/alt-text/#image-is-link)."`
`"Images inside a link tag require alt text that describes the purpose of the link (https://doublegreat.dev/alt-text/#image-is-link)."`,
);
});
it("`docs` matches generated GitHub `heading` link", async () => {
expect.assertions(1);
await expect(checkDocsLink(imageLink.heading)).resolves.toEqual(
imageLink.docs
imageLink.docs,
);
});
});
2 changes: 1 addition & 1 deletion src/clues/__tests__/no-alt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("noAlt", () => {
});
it("check", () => {
expect(noAlt.check()).toMatchInlineSnapshot(
`"Missing "alt" attribute (https://doublegreat.dev/alt-text/#missing-alt-attribute)."`
`"Missing "alt" attribute (https://doublegreat.dev/alt-text/#missing-alt-attribute)."`,
);
});
it("`docs` matches generated GitHub `heading` link", async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/clues/__tests__/not-only-space.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("notOnlySpace", () => {
it("`docs` matches generated GitHub `heading` link", async () => {
expect.assertions(1);
await expect(checkDocsLink(notOnlySpace.heading)).resolves.toEqual(
notOnlySpace.docs
notOnlySpace.docs,
);
});
});
2 changes: 1 addition & 1 deletion src/clues/__tests__/start-with.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("altStartsWith", () => {
it("`docs` matches generated GitHub `heading` link", async () => {
expect.assertions(1);
await expect(checkDocsLink(altStartsWith.heading)).resolves.toEqual(
altStartsWith.docs
altStartsWith.docs,
);
});
});
2 changes: 1 addition & 1 deletion src/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const formattedDocs = `## Suggestions
${allClues
.map(
(clue) =>
`- [${clue.heading} (\`${clue.id}\`)](#${slugger.slug(clue.heading)})`
`- [${clue.heading} (\`${clue.id}\`)](#${slugger.slug(clue.heading)})`,
)
.join("\n")}

Expand Down
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import altStartsWith from "./clues/start-with.js";
*/
export default function altText(
alt: string | undefined,
config?: Config
config?: Config,
): string | undefined {
// lowercase alt text to improve parsing
alt = alt?.toLowerCase();
Expand Down Expand Up @@ -49,8 +49,8 @@ export default function altText(
let suggestion: string[] | [] = [];
for (const rule of rules) {
// get the rule's id
const ruleConfig: ConfigOption = config[rule.id];
// skip rule if it is diabled
const ruleConfig = config[rule.id as keyof Config];
// skip rule if it is disabled
if (ruleConfig === false) continue;
// check rule and add any suggestions
suggestion = [...suggestion, ...rule.check(alt, ruleConfig)];
Expand All @@ -76,7 +76,6 @@ export const defaultConfig: Config = {
export type Alt = string;

export type Config = {
[key: string]: any; // TO DO, remove!
"image-is-decorative"?: boolean;
"avoid-emoji"?: boolean;
"contains-unhelpful-word"?: boolean | { exclude: string[] };
Expand Down