Skip to content

Commit 3cc0c91

Browse files
authored
feat(eslint-config): wrap long comments (#49)
Prettier explicitly ignores comments. However, scrolling to read comments is getting old quick, so explicitly wrapping them. This may interfere with ascii-schema comments, but is pretty easy to disable for that specific multi-line block. Signed-off-by: Dirk de Visser <[email protected]>
1 parent ff90caf commit 3cc0c91

File tree

11 files changed

+3280
-31
lines changed

11 files changed

+3280
-31
lines changed

apps/backend/plugins/base.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ async function base(
1919
.setValidatorCompiler(validatorCompiler)
2020
.setSerializerCompiler(serializerCompiler);
2121

22-
// TODO: should only be enabled for specific plugin contexts. So we may want to expose a
23-
// function with these defaults at some point?
22+
// TODO: should only be enabled for specific plugin contexts. So we may want to expose a function
23+
// with these defaults at some point?
2424

2525
await app.register(fastifyMultipart, {
2626
limits: {
@@ -48,8 +48,7 @@ async function base(
4848
},
4949
attachFieldsToBody: true,
5050

51-
// TODO: with these limits, we probably want to specify an 'onFile' and save temporary to
52-
// disk.
51+
// TODO: with these limits, we probably want to specify an 'onFile' and save temporary to disk.
5352

5453
...options.multipart,
5554
});

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"private": true,
55
"license": "MIT",
66
"scripts": {
7+
"postinstall": "patch-package",
78
"lint:ws": "npm run lint --workspaces --if-present --include-workspace-root",
89
"lint:ci:ws": "npm run lint:ci --workspaces --if-present --include-workspace-root",
910
"build:ws": "npm run build && npm run build --workspaces --if-present",
@@ -17,6 +18,7 @@
1718
"devDependencies": {
1819
"@lightbase/eslint-config": "0.1.0",
1920
"@lightbase/tsconfig": "0.1.0",
21+
"patch-package": "8.0.0",
2022
"typescript": "5.4.5"
2123
},
2224
"engines": {

packages/eslint-config/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"eslint": "^8.57.0",
3232
"eslint-config-flat-gitignore": "^0.1.5",
3333
"eslint-import-resolver-typescript": "^3.6.1",
34+
"eslint-plugin-comment-length": "1.7.3",
3435
"eslint-plugin-file-progress": "^1.3.0",
3536
"eslint-plugin-import-x": "^0.5.0",
3637
"eslint-plugin-jsdoc": "^48.2.3",

packages/eslint-config/src/globs.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ export const GLOBS = {
1717
};
1818

1919
/**
20-
* Keep track of all used globs. We need this to use custom globs for running Prettier in
21-
* ESLint.
20+
* Keep track of all used globs. We need this to use custom globs for running Prettier in ESLint.
2221
*/
2322
export function globUse(globs: Array<string>) {
2423
for (const glob of globs) {
@@ -50,9 +49,8 @@ export function globMarkdownSnippetFromGlob(glob: string) {
5049
}
5150

5251
/**
53-
* Register all globs in use by custom configs. This is needed since we apply
54-
* those after the Prettier configuration. The Prettier config then uses a processor
55-
* to prevent parser conflicts.
52+
* Register all globs in use by custom configs. This is needed since we apply those after the
53+
* Prettier configuration. The Prettier config then uses a processor to prevent parser conflicts.
5654
*/
5755
export function globUseFromUserConfig(...userConfigs: Array<FlatConfig.Config>) {
5856
for (const conf of userConfigs) {

packages/eslint-config/src/imports.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export function imports(): Array<FlatConfig.Config> {
88
return [
99
{
1010
// Setup import plugins. Includes unused-imports, to automatically remove them.
11-
// This might not be the best experience if imports are added manually, but most people
12-
// use auto-imports anyway (?!).
11+
// This might not be the best experience if imports are added manually,
12+
// but most people use auto-imports anyway (?!).
1313
files: globUse([GLOBS.javascript, GLOBS.typescript]),
1414
plugins: {
1515
"import-x": pluginImport.default,
@@ -82,8 +82,8 @@ export function imports(): Array<FlatConfig.Config> {
8282
"import-x/no-named-as-default": "off",
8383
"import-x/no-named-as-default-member": "off",
8484

85-
// Re-enable once <https://github.com/import-js/eslint-plugin-import/issues/1479> is
86-
// fixed. There is currently no related issue in eslint-plugin-import-x repo yet.
85+
// Re-enable once <https://github.com/import-js/eslint-plugin-import/issues/1479> is fixed.
86+
// There is currently no related issue in eslint-plugin-import-x repo yet.
8787
"import-x/no-duplicates": "off",
8888
},
8989
},

packages/eslint-config/src/javascript.ts

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
import eslintConfigs from "@eslint/js";
22
import typescriptEslintParser from "@typescript-eslint/parser";
33
import type { FlatConfig } from "@typescript-eslint/utils/ts-eslint";
4+
// @ts-expect-error no type defs
5+
import eslintPluginCommentLength from "eslint-plugin-comment-length";
46
import pluginJsDoc from "eslint-plugin-jsdoc";
57
import { GLOBS, globUse } from "./globs.js";
68
import { lightbaseInternalPlugin } from "./plugin/index.js";
79

810
export function javascript(): Array<FlatConfig.Config> {
11+
const commentLengthOptions = {
12+
mode: "overflow-only",
13+
maxLength: 100,
14+
logicalWrap: false,
15+
tabSize: 2,
16+
ignoreUrls: true,
17+
ignoreCommentsWithCode: false,
18+
tags: [],
19+
};
20+
921
return [
1022
{
11-
// Use the Typescript parser even if we don't Typescript. This allows us to use 'modern'
12-
// JS features even if the built-in espree parser doesn't support it.
23+
// Use the Typescript parser even if we don't Typescript. This allows us to use 'modern' JS
24+
// features even if the built-in espree parser doesn't support it.
1325
files: globUse([GLOBS.javascript]),
1426
languageOptions: {
1527
parser: typescriptEslintParser,
@@ -125,5 +137,17 @@ export function javascript(): Array<FlatConfig.Config> {
125137
"jsdoc/valid-types": "off",
126138
},
127139
},
140+
141+
{
142+
// Apply formatting on comments.
143+
files: globUse([GLOBS.javascript, GLOBS.typescript]),
144+
plugins: {
145+
"comment-length": eslintPluginCommentLength as unknown as FlatConfig.Plugin,
146+
},
147+
rules: {
148+
"comment-length/limit-single-line-comments": ["error", commentLengthOptions],
149+
"comment-length/limit-multi-line-comments": ["error", commentLengthOptions],
150+
},
151+
},
128152
] satisfies Array<FlatConfig.Config>;
129153
}

packages/eslint-config/src/plugin/node-builtin-module-url-import.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export const nodeBuiltinModuleUrlImport: AnyRuleModule = {
2525
create(context) {
2626
return {
2727
ImportDeclaration(node) {
28-
// Note that builtinModules doesn't include the `node:` specifier, so we automatically skip these once fixed.
28+
// Note that builtinModules doesn't include the `node:` specifier, so we automatically skip
29+
// these once fixed.
2930
if (!builtinModules.includes(node.source.value)) {
3031
return;
3132
}

packages/eslint-config/src/prettier.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function prettierConfig(config?: PrettierConfig) {
3737

3838
const defaultConfig = {
3939
printWidth: 90,
40+
tabWidth: 2,
4041
useTabs: true,
4142
semi: true,
4243
singleQuote: false,
@@ -52,8 +53,8 @@ export function prettierConfig(config?: PrettierConfig) {
5253
};
5354
config.languageOverrides ??= {};
5455

55-
// Dynamically add processors. We need just the original source to pass to Prettier. So if
56-
// the file is already parsed by another ESLint parser, we need to create a virtual file.
56+
// Dynamically add processors. We need just the original source to pass to Prettier. So if the
57+
// file is already parsed by another ESLint parser, we need to create a virtual file.
5758
const processors: Array<FlatConfig.Config> = [];
5859
const selectGlob = (a: string, processor: FlatConfig.Processor) => {
5960
if (globIsUsed(a)) {
@@ -172,11 +173,11 @@ export function prettierConfig(config?: PrettierConfig) {
172173
}
173174

174175
/**
175-
* Make files available under a `.format` extension. This is necessary for all filetypes
176-
* that have a custom parser configured.
176+
* Make files available under a `.format` extension. This is necessary for all filetypes that have
177+
* a custom parser configured.
177178
*
178-
* ESLint only supports a single parser per file-type. Through config merging, the 'plain'
179-
* parser we use above would always overwrite specific parsers.
179+
* ESLint only supports a single parser per file-type. Through config merging, the 'plain' parser
180+
* we use above would always overwrite specific parsers.
180181
*
181182
* This is kinda hacky and not exactly sure what the consequences are yet...
182183
*/
@@ -187,8 +188,8 @@ function formatProcessor(): FlatConfig.Processor {
187188
version: "-",
188189
},
189190
preprocess(text: string, filename: string): Array<string | Linter.ProcessorFile> {
190-
// Passes through the original file, and includes one with the `.format` prefix. This
191-
// is also called a 'virtual' file.
191+
// Passes through the original file, and includes one with the `.format` prefix. This is also
192+
// called a 'virtual' file.
192193
return [
193194
text,
194195
{

packages/eslint-config/src/react.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export type ReactConfig = {
1414
};
1515

1616
export async function react(config: ReactConfig): Promise<Array<FlatConfig.Config>> {
17-
// Only expect the Next.js plugin if explicitly enabled.
18-
// At some point we might infer this based on existence of the `next.config.js` file?
17+
// Only expect the Next.js plugin if explicitly enabled. At some point we might infer this based
18+
// on the existence of the `next.config.js` file?
1919
const pluginNext =
2020
config.withNextJs ?
2121
(

packages/eslint-config/src/typescript.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export type TypescriptConfig =
1616
* explicitly passed.
1717
*
1818
* Prefers `tsconfig.eslint.json` over `tsconfig.json`. This distinction might be necessary,
19-
* since typescript-eslint expects all files to be part of the compile unit, but that might
20-
* not be needed for normal builds.
19+
* since typescript-eslint expects all files to be part of the compile unit, but that might not be
20+
* needed for normal builds.
2121
*/
2222
export function typescriptResolveConfig(config?: TypescriptConfig): TypescriptConfig {
2323
if (config === false) {
@@ -43,9 +43,9 @@ export function typescriptResolveConfig(config?: TypescriptConfig): TypescriptCo
4343
config = false;
4444
}
4545
} else if (config.project === undefined) {
46-
// An empty options object is passed, or an options object without project. Resolve
47-
// project as if nothing was passed. This means that we might disable Typescript support
48-
// even if the user explicitly passed `typescript: {}`.
46+
// An empty options object is passed, or an options object without project. Resolve project as
47+
// if nothing was passed. This means that we might disable Typescript support even if the user
48+
// explicitly passed `typescript: {}`.
4949
const emptyConfigResolved = typescriptResolveConfig(undefined);
5050

5151
if (

0 commit comments

Comments
 (0)