Skip to content

Commit

Permalink
feat: migrated packages to eslint v9 (#23)
Browse files Browse the repository at this point in the history
* feat: migrated packages to eslint v9

* chore: moved Readme to packages

* refactor: removed unwanted config
  • Loading branch information
jhasuraj01 authored Oct 2, 2024
1 parent 4b98289 commit 90d7e28
Show file tree
Hide file tree
Showing 39 changed files with 437 additions and 1,390 deletions.
4 changes: 0 additions & 4 deletions apps/cli-app/.eslintrc.json

This file was deleted.

8 changes: 8 additions & 0 deletions apps/cli-app/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @ts-check

import { baseConfigs, nodeConfigs } from "@organization/eslint-config";

export default [
...baseConfigs,
...nodeConfigs,
];
4 changes: 2 additions & 2 deletions apps/cli-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
},
"scripts": {
"preinstall": "npx only-allow pnpm",
"lint": "eslint ./src/**/* ./test/**/* --ext .ts,js --fix",
"lint:check": "eslint ./src/**/* ./test/**/* --ext .ts,js",
"lint": "eslint ./src/**/* ./test/**/* --fix",
"lint:check": "eslint ./src/**/* ./test/**/*",
"format": "prettier ./src/**/* ./test/**/* --write",
"format:check": "prettier ./src/**/* ./test/**/* --check",
"build": "tsup",
Expand Down
3 changes: 3 additions & 0 deletions apps/cli-app/src/hello.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ export const helloCommand = new Command()
.description('say hello!')
.argument('<string>', 'name of the person to greet')
.action((str) => {
if (typeof str !== 'string') {
throw new Error('Invalid argument')
}
console.log(`Hello, ${str}!`)
})
56 changes: 56 additions & 0 deletions devpacks/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@organization/eslint-config",
"version": "0.0.0",
"description": "Default EsLint Configuration for Packages",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"node": "./dist/index.cjs",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
}
},
"scripts": {
"preinstall": "npx only-allow pnpm",
"format": "prettier ./src/**/* --write",
"format:check": "prettier ./src/**/* --check",
"build": "tsup",
"dev": "tsup --watch",
"clear": "rimraf dist",
"clear:all": "rimraf dist node_modules",
"typecheck:src": "tsc -p ./tsconfig.json --noEmit"
},
"keywords": [],
"author": {
"email": "contact@jhasuraj.com",
"name": "Suraj Jha",
"url": "https://jhasuraj.com"
},
"contributors": [],
"license": "MIT",
"engines": {
"node": "20.17.0",
"pnpm": "9.12.0"
},
"engineStrict": true,
"packageManager": "pnpm@9.12.0",
"devDependencies": {
"@eslint/js": "^9.11.1",
"@organization/tsconfig": "workspace:*",
"@organization/tsup": "workspace:*",
"@types/eslint-config-prettier": "^6.11.3",
"@types/eslint__js": "^8.42.3",
"eslint": "^9.11.1",
"eslint-config-prettier": "^9.1.0",
"globals": "^15.10.0",
"rimraf": "^6.0.1",
"tsup": "^8.3.0",
"typescript-eslint": "^8.8.0"
},
"nx": {}
}
26 changes: 26 additions & 0 deletions devpacks/eslint-config/src/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import eslint from "@eslint/js";
import tseslint, { Config } from "typescript-eslint";
import prettier from "eslint-config-prettier";

const strictTypeChecked = tseslint.configs.strictTypeChecked;
const stylisticTypeChecked = tseslint.configs.stylisticTypeChecked;

export const baseConfigs: Awaited<Config> = [
{
files: ["**/*.{js,mjs,cjs,ts,tsx,jsx}"],
linterOptions: {
noInlineConfig: true,
},
languageOptions: {
parserOptions: {
project: ["./tsconfig.json", "./test/tsconfig.json"],
},
ecmaVersion: "latest",
sourceType: "module",
},
},
eslint.configs.recommended,
...strictTypeChecked,
...stylisticTypeChecked,
prettier,
];
12 changes: 12 additions & 0 deletions devpacks/eslint-config/src/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import globals from "globals";
import type { Config } from "typescript-eslint";

export const browserConfigs: Awaited<Config> = [
{
languageOptions: {
globals: {
...globals.browser,
},
},
},
];
3 changes: 3 additions & 0 deletions devpacks/eslint-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./base";
export * from "./node";
export * from "./browser";
12 changes: 12 additions & 0 deletions devpacks/eslint-config/src/node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import globals from "globals";
import type { Config } from "typescript-eslint";

export const nodeConfigs: Awaited<Config> = [
{
languageOptions: {
globals: {
...globals.node,
},
},
},
];
17 changes: 17 additions & 0 deletions devpacks/eslint-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@organization/tsconfig",
"compilerOptions": {
"baseUrl": "./",
"rootDir": "src",
"outDir": "dist",
"declarationDir": "dist"
},
"include": [
"./src/**/*.ts"
],
"exclude": [
"node_modules",
"dist"
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions devpacks/scripts/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @ts-check

import { baseConfigs, nodeConfigs } from "@organization/eslint-config";

export default [
...baseConfigs,
...nodeConfigs,
];
4 changes: 2 additions & 2 deletions scripts/package.json → devpacks/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
},
"scripts": {
"preinstall": "npx only-allow pnpm",
"lint": "eslint ./src/**/* ./test/**/* --ext .ts,js --fix",
"lint:check": "eslint ./src/**/* ./test/**/* --ext .ts,js",
"lint": "eslint ./src/**/* ./test/**/* --fix",
"lint:check": "eslint ./src/**/* ./test/**/*",
"format": "prettier ./src/**/* ./test/**/* --write",
"format:check": "prettier ./src/**/* ./test/**/* --check",
"build": "tsup",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ async function findLatestPackageVersion(packageName: string): Promise<string> {

async function findLatestNodeLTSVersion(): Promise<string> {
const response = await fetch('https://nodejs.org/dist/index.json')
const data = (await response.json()) as Array<{
const data = (await response.json()) as {
version: string
lts: string | false
}>
}[]
const ltsVersion = data.find((v) => v.lts)?.version
if (ltsVersion === undefined) {
throw new Error('Could not find latest LTS version')
Expand Down Expand Up @@ -77,7 +77,7 @@ async function main(baseDir: string): Promise<void> {
const latestNodeVersion = await findLatestNodeLTSVersion()

// update package.json files
for await (const file of packageJsonFiles) {
for (const file of packageJsonFiles) {
await updatePackageJson(file, latestNodeVersion, latestPnpmVersion)
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions devpacks/scripts/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { tsup } from '@organization/tsup';
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions packages/tsup/package.json → devpacks/tsup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,26 @@
"types": "./dist/index.d.ts",
"node": "./dist/index.cjs",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"default": "./dist/index.js"
"import": "./dist/index.mjs"
}
},
"scripts": {
"preinstall": "npx only-allow pnpm",
"lint": "eslint ./src/**/* tsup.config.ts --ext .ts,js --fix",
"lint:check": "eslint ./src/**/* tsup.config.ts --ext .ts,js",
"build": "tsup",
"dev": "tsup --watch",
"clear": "rimraf dist",
"clear:all": "rimraf dist node_modules",
"typecheck:src": "tsc -p ./tsconfig.json --noEmit"
},
"devDependencies": {
"@organization/eslint-config": "workspace:*",
"@organization/tsconfig": "workspace:*",
"rimraf": "^6.0.1",
"tsup": "^8.3.0",
"typescript": "^5.6.2"
},
"peerDependencies": {
"tsup": "^8.3.0"
},
"keywords": [],
"author": {
"email": "contact@jhasuraj.com",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { defineConfig } from 'tsup'
export const tsup = defineConfig((options) => {
const isWatchMode = Boolean(options.watch)
return {
format: isWatchMode ? ['esm', 'cjs'] : ['esm', 'cjs', 'iife'],
// format: isWatchMode ? ['esm', 'cjs'] : ['esm', 'cjs', 'iife'],
format: ['esm', 'cjs'],
outExtension: ({ format }) => {
if (format === 'esm') {
return {
Expand Down
22 changes: 0 additions & 22 deletions packages/eslint-config/.eslintrc.json

This file was deleted.

41 changes: 0 additions & 41 deletions packages/eslint-config/package.json

This file was deleted.

4 changes: 0 additions & 4 deletions packages/hello/.eslintrc.json

This file was deleted.

9 changes: 9 additions & 0 deletions packages/hello/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @ts-check

import { baseConfigs, browserConfigs, nodeConfigs } from "@organization/eslint-config";

export default [
...baseConfigs,
...nodeConfigs,
...browserConfigs,
];
7 changes: 3 additions & 4 deletions packages/hello/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
"types": "./dist/index.d.ts",
"node": "./dist/index.cjs",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"default": "./dist/index.js"
"import": "./dist/index.mjs"
}
},
"scripts": {
"preinstall": "npx only-allow pnpm",
"lint": "eslint ./src/**/* ./test/**/* --ext .ts,js --fix",
"lint:check": "eslint ./src/**/* ./test/**/* --ext .ts,js",
"lint": "eslint ./src/**/* ./test/**/* --fix",
"lint:check": "eslint ./src/**/* ./test/**/*",
"format": "prettier ./src/**/* ./test/**/* --write",
"format:check": "prettier ./src/**/* ./test/**/* --check",
"build": "tsup",
Expand Down
4 changes: 0 additions & 4 deletions packages/tsup/.eslintrc.json

This file was deleted.

Loading

0 comments on commit 90d7e28

Please sign in to comment.