Skip to content

Commit

Permalink
feat(eslint-config): fully add the Prettier options and reformat (#21)
Browse files Browse the repository at this point in the history
Signed-off-by: Dirk de Visser <[email protected]>
  • Loading branch information
dirkdev98 authored Mar 6, 2024
1 parent 43ea769 commit 6326791
Show file tree
Hide file tree
Showing 16 changed files with 369 additions and 246 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Automatically assign pull requests

* @lightbasenl/core
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ on:
pull_request:

concurrency:
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
group:
"${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref
|| github.ref }}"
cancel-in-progress: true

jobs:
Expand Down
64 changes: 32 additions & 32 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
{
"name": "@workspace/backend",
"type": "module",
"private": true,
"license": "MIT",
"scripts": {
"build": "tsc -p ./tsconfig.json",
"lint": "eslint . --fix --cache --cache-strategy content --cache-location .cache/eslint/ --color",
"lint:ci": "eslint .",
"pretest": "npm run build",
"test": "node --test"
},
"dependencies": {
"@fastify/helmet": "^11.1.1",
"@fastify/multipart": "^8.1.0",
"close-with-grace": "^1.2.0",
"dotenv": "^16.4.4",
"fastify": "^4.26.0",
"fastify-custom-healthcheck": "^3.1.0",
"fastify-plugin": "^4.5.1",
"fastify-type-provider-zod": "^1.1.9",
"zod": "^3.22.4"
},
"devDependencies": {
"@types/node": "^20.11.17",
"@lightbase/tsconfig": "0.1.0",
"@lightbase/eslint-config": "0.1.0",
"pino-pretty": "^10.3.1",
"typescript": "5.3.3"
},
"engines": {
"node": ">=20"
}
"name": "@workspace/backend",
"type": "module",
"private": true,
"license": "MIT",
"scripts": {
"build": "tsc -p ./tsconfig.json",
"lint": "eslint . --fix --cache --cache-strategy content --cache-location .cache/eslint/ --color",
"lint:ci": "eslint .",
"pretest": "npm run build",
"test": "node --test"
},
"dependencies": {
"@fastify/helmet": "^11.1.1",
"@fastify/multipart": "^8.1.0",
"close-with-grace": "^1.2.0",
"dotenv": "^16.4.4",
"fastify": "^4.26.0",
"fastify-custom-healthcheck": "^3.1.0",
"fastify-plugin": "^4.5.1",
"fastify-type-provider-zod": "^1.1.9",
"zod": "^3.22.4"
},
"devDependencies": {
"@types/node": "^20.11.17",
"@lightbase/tsconfig": "0.1.0",
"@lightbase/eslint-config": "0.1.0",
"pino-pretty": "^10.3.1",
"typescript": "5.3.3"
},
"engines": {
"node": ">=20"
}
}
8 changes: 4 additions & 4 deletions apps/backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "@lightbase/tsconfig/node-package.json",
"compilerOptions": {
"outDir": "dist",
}
"extends": "@lightbase/tsconfig/node-package.json",
"compilerOptions": {
"outDir": "dist"
}
}
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "@lightbase/platforms",
"type": "module",
"private": true,
"license": "MIT",
"scripts": {
"lint:ws": "npm run lint --workspaces --if-present --include-workspace-root",
"lint:ci:ws": "npm run lint:ci --workspaces --if-present --include-workspace-root",
"build:ws": "npm run build && npm run build --workspaces --if-present",
"test:ws": "npm run test --workspaces --if-present --include-workspace-root",
"build": "tsc --build",
"lint": "eslint . --fix --cache --cache-strategy content --cache-location .cache/eslint/ --color",
"lint:ci": "eslint ."
},
"devDependencies": {
"@lightbase/tsconfig": "0.1.0",
"@lightbase/eslint-config": "0.1.0",
"typescript": "5.3.3"
},
"engines": {
"node": ">=20"
},
"workspaces": ["packages/*", "apps/*"]
"name": "@lightbase/platforms",
"type": "module",
"private": true,
"license": "MIT",
"scripts": {
"lint:ws": "npm run lint --workspaces --if-present --include-workspace-root",
"lint:ci:ws": "npm run lint:ci --workspaces --if-present --include-workspace-root",
"build:ws": "npm run build && npm run build --workspaces --if-present",
"test:ws": "npm run test --workspaces --if-present --include-workspace-root",
"build": "tsc --build",
"lint": "eslint . --fix --cache --cache-strategy content --cache-location .cache/eslint/ --color",
"lint:ci": "eslint ."
},
"devDependencies": {
"@lightbase/eslint-config": "0.1.0",
"@lightbase/tsconfig": "0.1.0",
"typescript": "5.3.3"
},
"engines": {
"node": ">=20"
},
"workspaces": ["packages/*", "apps/*"]
}
33 changes: 31 additions & 2 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,38 @@ alpha.
- Use `eslint.config.mjs` instead of `eslint.config.js`
- Specify `--config eslint.config.mjs` in the `package.json` scripts.

## Options
## Default configuration and options

None yet...
### Markdown

A Markdown parser is installed by default. One of its purposes is to extract code-blocks
and present them as virtual files. Other configurations will automatically handle these
since they glob on `**/`.

### Prettier

Prettier is configured to run on all markdown, json, yaml, JavaScript and TypeScript
files. We support the following configuration to override this:

```js
import { defineConfig } from "@lightbase/eslint-config";

export default defineConfig({
prettier: {
globalOverride: {
// Override Prettier options for all supported files.
},
languageOverrides: {
ts: {
// Override Prettier options for a specific file
// group.
},
},
},
});
```

None of these options are required.

## Custom configuration

Expand Down
66 changes: 33 additions & 33 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
{
"name": "@lightbase/eslint-config",
"version": "0.1.0",
"type": "module",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"exports": {
".": {
"import": "./dist/src/index.js"
}
},
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"files": ["README.md", "LICENSE", "dist/"],
"engines": {
"node": ">=20"
},
"scripts": {
"lint": "eslint . --fix --cache --cache-strategy content --cache-location .cache/eslint/ --color",
"lint:ci": "eslint ."
},
"dependencies": {
"eslint-plugin-format": "^0.1.0",
"eslint-plugin-markdown": "^3.0.1"
},
"peerDependencies": {
"eslint": ">=8.56.0"
},
"devDependencies": {
"@types/eslint": "^8.56.2",
"@types/eslint-plugin-markdown": "^2.0.2"
}
"name": "@lightbase/eslint-config",
"version": "0.1.0",
"type": "module",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"exports": {
".": {
"import": "./dist/src/index.js"
}
},
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"files": ["README.md", "LICENSE", "dist/"],
"engines": {
"node": ">=20"
},
"scripts": {
"lint": "eslint . --fix --cache --cache-strategy content --cache-location .cache/eslint/ --color",
"lint:ci": "eslint ."
},
"dependencies": {
"eslint-plugin-format": "^0.1.0",
"eslint-plugin-markdown": "^3.0.1"
},
"peerDependencies": {
"eslint": ">=8.56.0"
},
"devDependencies": {
"@types/eslint": "^8.56.2",
"@types/eslint-plugin-markdown": "^2.0.2"
}
}
77 changes: 8 additions & 69 deletions packages/eslint-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
import { Linter } from "eslint";
import format from "eslint-plugin-format";
import markdown from "eslint-plugin-markdown";
import { markdownConfig } from "./markdown.js";
import { PrettierConfig, prettierConfig } from "./prettier.js";

interface Opts {}
interface Opts {
prettier?: PrettierConfig;
}

export function defineConfig(opts: Opts, ...config: Linter.FlatConfig[]) {
// TODO: Global prettier config

// TODO: Prettier config overrides per supported file type.

const prettierConfig = {
printWidth: 90,
useTabs: true,
semi: true,
singleQuote: false,
quoteProps: "consistent",
trailingComma: "all",
bracketSpacing: true,
arrowParens: "always",
proseWrap: "always",
endOfLine: "lf",
experimentalTernaries: true,
};

const conf: Linter.FlatConfig[] = [
{
// TODO: Add automatic ignores based on .gitignore
ignores: [".cache", ".idea", ".next", "dist", "out"],
ignores: [".cache", ".idea", ".next", "dist", "out", "package-lock.json"],
},

{
Expand All @@ -36,53 +20,8 @@ export function defineConfig(opts: Opts, ...config: Linter.FlatConfig[]) {
},
},

{
plugins: {
markdown,
},
},
{
files: ["**/*.md"],
languageOptions: {
parser: format.parserPlain,
},
},
{
files: ["**/*.md"],
languageOptions: {
parser: format.parserPlain,
},
plugins: {
format,
},
rules: {
"format/prettier": ["error", { parser: "markdown", ...prettierConfig }],
},
},
{
files: ["**/*.[yml,yaml]"],
languageOptions: {
parser: format.parserPlain,
},
plugins: {
format,
},
rules: {
"format/prettier": ["error", { parser: "yaml", ...prettierConfig }],
},
},
{
files: ["**/*.?([cm])[jt]s?(x)"],
languageOptions: {
parser: format.parserPlain,
},
plugins: {
format,
},
rules: {
"format/prettier": ["error", { parser: "typescript", ...prettierConfig }],
},
},
...markdownConfig(),
...prettierConfig(opts.prettier),
];

return conf.concat(...config);
Expand Down
15 changes: 15 additions & 0 deletions packages/eslint-config/src/markdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Linter } from "eslint";
import markdown from "eslint-plugin-markdown";

/**
* Allows parsing of markdown files, adding code blocks as virtual files.
*/
export function markdownConfig(): Linter.FlatConfig[] {
return [
{
plugins: {
markdown,
},
},
];
}
Loading

0 comments on commit 6326791

Please sign in to comment.