Skip to content

Commit

Permalink
chore: Update lint configuration (ESLint 9, Prettier 3) (#2438)
Browse files Browse the repository at this point in the history
* Update linting configuration (eslint, prettier)

* Fix lint issues following eslint prettier update

* Change ESLint config to allow boolean coercion

* Switch to default import name per docs

* Fix suppression of error details

* Update JSDoc comments

* Update waiForFunctin to provide error details

---------

Co-authored-by: Koy Zhuang <[email protected]>
  • Loading branch information
jhildenbiddle and Koooooo-7 authored May 28, 2024
1 parent 6552853 commit f5412dc
Show file tree
Hide file tree
Showing 59 changed files with 744 additions and 994 deletions.
11 changes: 0 additions & 11 deletions .eslintignore

This file was deleted.

83 changes: 0 additions & 83 deletions .eslintrc.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion build/cover.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ let cover = read(file, 'utf8').toString();
console.log('Replace version number in cover page...');
cover = cover.replace(
/<small>(\S+)?<\/small>/g,
/* html */ `<small>${version}</small>`
/* html */ `<small>${version}</small>`,
);
write(file, cover);
14 changes: 7 additions & 7 deletions build/emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const filePaths = {
'src',
'core',
'render',
'emoji-data.js'
'emoji-data.js',
),
};

Expand All @@ -26,7 +26,7 @@ async function getEmojiData() {

// Remove base URL from emoji URLs
Object.entries(data).forEach(
([key, value]) => (data[key] = value.replace(baseURL, ''))
([key, value]) => (data[key] = value.replace(baseURL, '')),
);

console.info(`- Retrieved ${Object.keys(data).length} emoji entries`);
Expand All @@ -41,7 +41,7 @@ function writeEmojiPage(emojiData) {
const isExistingPage = fs.existsSync(filePaths.emojiMarkdown);
const emojiPage =
(isExistingPage && fs.readFileSync(filePaths.emojiMarkdown, 'utf8')) ||
`<!-- START -->\n\n<!-- END -->`;
'<!-- START -->\n\n<!-- END -->';
const emojiRegEx = /(<!--\s*START.*-->\n)([\s\S]*)(\n<!--\s*END.*-->)/;
const emojiMatch = emojiPage.match(emojiRegEx);
const emojiMarkdownStart = emojiMatch[1].trim();
Expand All @@ -51,20 +51,20 @@ function writeEmojiPage(emojiData) {
.reduce(
(preVal, curVal) =>
(preVal += `:${curVal}: ` + '`' + `:${curVal}:` + '`' + '\n\n'),
''
'',
)
.trim();

if (emojiMarkdown !== newEmojiMarkdown) {
const newEmojiPage = emojiPage.replace(
emojiMatch[0],
`${emojiMarkdownStart}\n\n${newEmojiMarkdown}\n\n${emojiMarkdownEnd}`
`${emojiMarkdownStart}\n\n${newEmojiMarkdown}\n\n${emojiMarkdownEnd}`,
);

fs.writeFileSync(filePaths.emojiMarkdown, newEmojiPage);

console.info(
`- ${!isExistingPage ? 'Created' : 'Updated'}: ${filePaths.emojiMarkdown}`
`- ${!isExistingPage ? 'Created' : 'Updated'}: ${filePaths.emojiMarkdown}`,
);
} else {
console.info(`- No changes: ${filePaths.emojiMarkdown}`);
Expand All @@ -86,7 +86,7 @@ function writeEmojiJS(emojiData) {
fs.writeFileSync(filePaths.emojiJS, newEmojiJS);

console.info(
`- ${!isExistingPage ? 'Created' : 'Updated'}: ${filePaths.emojiJS}`
`- ${!isExistingPage ? 'Created' : 'Updated'}: ${filePaths.emojiJS}`,
);
} else {
console.info(`- No changes: ${filePaths.emojiJS}`);
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
2 changes: 1 addition & 1 deletion docs/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ window.$docsify = {
return /* html */ `
<div class="mermaid">${mermaid.render(
'mermaid-svg-' + num++,
code
code,
)}</div>
`;
}
Expand Down
6 changes: 3 additions & 3 deletions docs/pwa.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ self.addEventListener('fetch', event => {
.then(resp => resp || fetched)
.catch(_ => {
/* eat any errors */
})
}),
);

// Update the cache with the version we fetched (only for ok status)
event.waitUntil(
Promise.all([fetchedCopy, caches.open(RUNTIME)])
.then(
([response, cache]) =>
response.ok && cache.put(event.request, response)
response.ok && cache.put(event.request, response),
)
.catch(_ => {
/* eat any errors */
})
}),
);
}
});
Expand Down
79 changes: 79 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import eslintConfigPrettier from 'eslint-config-prettier';
import playwrightPlugin from 'eslint-plugin-playwright';
import jestPlugin from 'eslint-plugin-jest';
import globals from 'globals';
import js from '@eslint/js';

export default [
// Ignore (Must be first item in array)
{
ignores: [
// Directories
'_playwright-*',
'dist',
'docs',
'lib',
'node_modules',
// Files
'**/*.md',
'CHANGELOG.md',
'emoji-data.*',
'HISTORY.md',
],
},
// ESLint Recommended
js.configs.recommended,
// Configuration: Prettier
eslintConfigPrettier,
// All Files
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
$docsify: 'readonly',
Docsify: 'readonly',
},
},
rules: {
'array-callback-return': ['error'],
'block-scoped-var': ['error'],
curly: ['error'],
'dot-notation': ['error'],
eqeqeq: ['error'],
'no-implicit-coercion': ['error', { boolean: false }],
'no-implicit-globals': ['error'],
'no-loop-func': ['error'],
'no-return-assign': ['error'],
'no-template-curly-in-string': ['error'],
'no-unneeded-ternary': ['error'],
'no-unused-vars': ['error', { args: 'none' }],
'no-useless-computed-key': ['error'],
'no-useless-return': ['error'],
'no-var': ['error'],
'prefer-const': [
'error',
{
destructuring: 'all',
},
],
},
},
// Source Files
{
files: ['src/**'],
rules: {
'no-console': ['warn'],
},
},
// Tests: E2E (Playwright)
{
files: ['test/e2e/**'],
...playwrightPlugin.configs['flat/recommended'],
},
// Tests: Integration & Unit (Jest)
{
files: ['test/{integration,unit}/**'],
...jestPlugin.configs['flat/recommended'],
},
];
2 changes: 1 addition & 1 deletion middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default async function middleware(request) {
const indexHTML = await fetch(indexURL).then(res => res.text());
const previewHTML = rewriteRules.reduce(
(html, rule) => html.replace(rule.match, rule.replace),
indexHTML
indexHTML,
);

return new Response(previewHTML, {
Expand Down
Loading

0 comments on commit f5412dc

Please sign in to comment.