Skip to content

Commit

Permalink
Eslint (#568)
Browse files Browse the repository at this point in the history
* 🐛 FIX: lint * to .

* 🎨 NEW: toolName default design update node & browser

* 🐛 FIX: lint internals

* ✨ NEW: ui

* stripper

* .

* a few easy ones

* handlers

* okay

* fix tests

* yop

* clean

* lints need build

* eslint stuff

* pck

* build
  • Loading branch information
jycouet authored Dec 14, 2023
1 parent 32a5cc3 commit 2aaacce
Show file tree
Hide file tree
Showing 31 changed files with 265 additions and 145 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-pots-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kitql/eslint-config': minor
---

bump to an actual working state
5 changes: 5 additions & 0 deletions .changeset/ten-socks-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kitql/helpers': patch
---

toolName default design update node & browser
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ jobs:

- name: 👌 Run nx affected
run: pnpm nx:affected
env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}

# - name: 🚧 Build Packages
# run: pnpm run build
Expand Down Expand Up @@ -59,10 +57,8 @@ jobs:
# with:
# nodeVersion: 18

- name: 🚧 Run nx all
run: pnpm nx:all
env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
- name: 🚧 Run nx build
run: pnpm nx:build

- name: ➕ Create template
run:
Expand Down
18 changes: 10 additions & 8 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
node_modules/
node_modules
dist/
build/
coverage/
.next/
.idea/
.svelte-kit/
pnpm-lock.yaml
.changeset/
website/docs/**/*.mdx
CHANGELOG.md
vite.config.ts.timestamp-*

package.json
build
pnpm-lock.yaml
CHANGELOG.md
stats.html

$houdini
$kitql
stats.html

db/
ROUTES_*
templates/

templates/
*.svg
ab.d.ts
4 changes: 3 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"dependsOn": ["^build"],
"cache": true
},
"lint": {},
"lint": {
"dependsOn": ["^build"]
},
"test:ci": {
"dependsOn": ["^build"],
"cache": true
Expand Down
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
"dev:w": "cd website && npm run dev",
"release:version": "npm run changeset version",
"release": "npm run build && changeset publish",
"build": "rimraf packages/*/dist && pnpm exec nx run-many --target=build",
"lint": "pnpm exec nx run-many --target=lint",
"test:ci": "pnpm exec nx run-many --target=test:ci --exclude=create-kitql-*",
"format": "pnpm exec nx run-many --target=format",
"nx:graph": "pnpm exec nx graph",
"nx:reset": "pnpm exec nx reset",
"nx:all": "pnpm exec nx run-many --target=build,lint,test:ci --exclude=create-kitql-*",
"nx:affected": "pnpm exec nx affected --target=build,lint,test:ci --exclude=create-kitql-*",
"lint": "pnpm nx run-many --target=lint",
"format": "pnpm nx run-many --target=format",
"nx:graph": "pnpm nx graph",
"nx:build": "rimraf packages/*/dist && pnpm nx run-many --target=build --exclude=create-kitql-*",
"nx:all": "pnpm nx run-many --target=build,lint,test:ci --exclude=create-kitql-*",
"nx:affected": "pnpm nx affected --target=build,lint,test:ci --exclude=create-kitql-*",
"nx:reset": "pnpm nx reset",
"reset": "git clean -xdf",
"up-dep": "pnpm -r up --latest"
},
Expand Down
17 changes: 8 additions & 9 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![](https://img.shields.io/npm/v/@kitql/eslint-config?color=&logo=npm)](https://www.npmjs.com/package/@kitql/eslint-config)
[![](https://img.shields.io/npm/dm/@kitql/eslint-config?&logo=npm)](https://www.npmjs.com/package/@kitql/eslint-config)

## 📖 Read the doc
## 📖 Read the doc

[![](https://img.shields.io/badge/Documentation%20of-kitql%20lint%20format-FF3E00.svg?style=flat&logo=stackblitz&logoColor=FF3E00)](https://kitql.dev/docs)

Expand All @@ -16,25 +16,24 @@ npm install @kitql/eslint-config --D
### eslint config

`.eslintrc.js`

```js
module.exports = {
extends: [
'@kitql',
],
extends: ['@kitql']
}
```

### prettier config

`.prettierrc.cjs`

```js
const config = require('@kitql/eslint-config/.prettierrc.cjs')

module.exports = {
...config,
...config
// Some custom things?
}

```

### usage
Expand All @@ -47,9 +46,9 @@ npm exec kitql-lint
npm exec kitql-lint --format
```

## ⭐️ Join us
## ⭐️ Join us

[![GitHub Repo stars](https://img.shields.io/github/stars/jycouet/kitql?logo=github&label=KitQL&color=#4ACC31)](https://github.com/jycouet/kitql)

💡 _[KitQL](https://www.kitql.dev/docs) itself is not a library, it's "nothing" but a collection of standalone libraries._

💡 _[KitQL](https://www.kitql.dev/docs) itself is not a library, it's "nothing" but a collection of
standalone libraries._
109 changes: 57 additions & 52 deletions packages/eslint-config/cmd.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,35 @@
#!/usr/bin/env node
import { Log, red } from '@kitql/helpers'
import { spawn, spawnSync } from 'child_process'
import { program, Option } from 'commander'
import fs from 'fs'

const log = new Log('kitql-lint')

program.addOption(new Option('-f, --format', 'format'))

program.parse(process.argv)
const options_cli = program.opts()

// console.info(`options_cli`, options_cli)

let pathPrettierIgnore = ''
try {
fs.statSync('.prettierignore')
pathPrettierIgnore = '.prettierignore'
} catch (error) {
try {
fs.statSync('../../.prettierignore')
pathPrettierIgnore = '../../.prettierignore'
} catch (error) {
// Still nothing
const findFileOrUp = fileName => {
// Find file recursively 4 levels max up
for (let i = 0; i < 4; i++) {
try {
const path = '../'.repeat(i) + fileName
if (fs.statSync(path)) {
return path
}
} catch (error) {
// nothing to do
}
}
}
if (!pathPrettierIgnore) {
console.error(`.prettierignore not found`)
process.exit(0)
}

let pathPrettierCjs = ''
try {
fs.statSync('.prettierrc.cjs')
pathPrettierCjs = '.prettierrc.cjs'
} catch (error) {
try {
fs.statSync('../../.prettierrc.cjs')
pathPrettierCjs = '../../.prettierrc.cjs'
} catch (error) {
// Still nothing
}
}
if (!pathPrettierCjs) {
console.error(`.prettierrc.cjs not found`)
process.exit(0)
log.error(red(`${fileName} not found`))
process.exit(1)
}

// --config <path>
let pathPrettierIgnore = findFileOrUp('.prettierignore')
let pathPrettierCjs = findFileOrUp('.prettierrc.cjs')

const format = options_cli.format ?? false

Expand All @@ -60,26 +45,46 @@ const cmdPrettier =
`${format ? ' --write' : ''}` +
// exec
` .`
spawnSync(cmdPrettier, {
let result_prettier = spawn(cmdPrettier, {
shell: true,
// cwd: process.cwd(),
stdio: 'inherit',
cwd: process.cwd(),
stdio: 'pipe',
})

// Then eslint
const cmdEsLint =
`eslint` +
// ignore?
` --ignore-path ${pathPrettierIgnore}` +
// format or not
`${format ? ' --fix' : ''} ` +
// exec
` "*"`
spawnSync(cmdEsLint, {
shell: true,
// cwd: process.cwd(),
stdio: 'inherit',
})
// let's not log anything when we are formating prettier
if (!format) {
const logPrettier = new Log('kitql-lint prettier')
result_prettier.stdout.on('data', data => {
logPrettier.error(data.toString())
})
}

result_prettier.on('close', code => {
// Then eslint
const cmdEsLint =
`eslint` +
// ignore?
` --ignore-path ${pathPrettierIgnore}` +
// format or not
`${format ? ' --fix' : ''}` +
// exec
` .`

// log.info(cmdEsLint)

let result_eslint = spawnSync(cmdEsLint, {
shell: true,
cwd: process.cwd(),
stdio: 'inherit',
})

// console.log(`cmdPrettier`, cmdPrettier)
// console.log(`cmdEsLint`, cmdEsLint)
if (result_eslint.status) {
log.error(red(`eslint failed, check logs above.`))
}

if (code === 0 && result_eslint.status === 0) {
log.success(`All good, your files looks great!`)
}

process.exit(code || result_eslint.status)
})
4 changes: 3 additions & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
},
"main": "index.cjs",
"scripts": {
"dev": "node ./cmd.js",
"lint": "node ./cmd.js",
"format": "node ./cmd.js -f",
"lint:example": "kitql-lint",
"format:example": "kitql-lint --format"
},
"dependencies": {
"@graphql-eslint/eslint-plugin": "3.20.1",
"@kitql/helpers": "0.8.7",
"@theguild/eslint-config": "^0.11.1",
"@theguild/prettier-config": "2.0.2",
"@trivago/prettier-plugin-sort-imports": "4.3.0",
Expand Down
1 change: 1 addition & 0 deletions packages/handles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"devDependencies": {
"@kitql/eslint-config": "workspace:*",
"@kitql/helpers": "workspace:*",
"@sveltejs/adapter-node": "1.3.1",
"@sveltejs/kit": "1.30.1",
"@sveltejs/package": "2.2.2",
Expand Down
5 changes: 4 additions & 1 deletion packages/handles/src/lib/hooks/handleProxies.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Log } from '@kitql/helpers'
import { error } from '@sveltejs/kit'

/**
Expand Down Expand Up @@ -55,7 +56,9 @@ export const handleProxies = options => {
duplex: 'half',
})
.catch(err => {
console.log('handleProxies ERROR', err)
const log = new Log('handleProxies')
console.error(err)
log.error('handleProxies ERROR')
throw err
})
}
Expand Down
6 changes: 3 additions & 3 deletions packages/helpers/src/lib/Log.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('kitql - helper - Log', () => {
%cyellow%c
%cyellowBright%c
",
"background-color: #00ffff",
"background-color: #1e90ff",
"",
"background-color: black",
"",
Expand Down Expand Up @@ -246,7 +246,7 @@ describe('kitql - helper - Log', () => {
expect(result).toMatchInlineSnapshot(`
[
"%c tool name %c with red: %cred%c and another %cred2%c",
"background-color: #00ffff",
"background-color: #1e90ff",
"",
"color: red",
"",
Expand All @@ -266,7 +266,7 @@ describe('kitql - helper - Log', () => {
expect(result).toMatchInlineSnapshot(`
[
"%c tool name %c with red: %cred%c and another %cred2%c",
"background-color: #00ffff",
"background-color: #1e90ff",
"",
"color: red",
"",
Expand Down
4 changes: 2 additions & 2 deletions packages/helpers/src/lib/Log.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('kitql - helper - Log', () => {
expect(spy).toHaveBeenCalledOnce()

expect(stry0(result)).toMatchInlineSnapshot(
'"[\\"\\\\u001b[106m tool name \\\\u001b[49m with all colors: \\\\n \\\\u001b[40mbgBlack\\\\u001b[49m\\\\n \\\\u001b[100mbgBlackBright\\\\u001b[49m\\\\n \\\\u001b[44mbgBlue\\\\u001b[49m\\\\n \\\\u001b[104mbgBlueBright\\\\u001b[49m\\\\n \\\\u001b[46mbgCyan\\\\u001b[49m\\\\n \\\\u001b[106mbgCyanBright\\\\u001b[49m\\\\n \\\\u001b[42mbgGreen\\\\u001b[49m\\\\n \\\\u001b[102mbgGreenBright\\\\u001b[49m\\\\n \\\\u001b[45mbgMagenta\\\\u001b[49m\\\\n \\\\u001b[105mbgMagentaBright\\\\u001b[49m\\\\n \\\\u001b[41mbgRed\\\\u001b[49m\\\\n \\\\u001b[101mbgRedBright\\\\u001b[49m\\\\n \\\\u001b[47mbgWhite\\\\u001b[49m\\\\n \\\\u001b[107mbgWhiteBright\\\\u001b[49m\\\\n \\\\u001b[43mbgYellow\\\\u001b[49m\\\\n \\\\u001b[103mbgYellowBright\\\\u001b[49m\\\\n \\\\u001b[30mblack\\\\u001b[39m\\\\n \\\\u001b[90mblackBright\\\\u001b[39m\\\\n \\\\u001b[34mblue\\\\u001b[39m\\\\n \\\\u001b[94mblueBright\\\\u001b[39m\\\\n \\\\u001b[1mbold\\\\u001b[22m\\\\n \\\\u001b[36mcyan\\\\u001b[39m\\\\n \\\\u001b[96mcyanBright\\\\u001b[39m\\\\n \\\\u001b[2mdim\\\\u001b[22m\\\\n \\\\u001b[90mgray\\\\u001b[39m\\\\n \\\\u001b[32mgreen\\\\u001b[39m\\\\n \\\\u001b[92mgreenBright\\\\u001b[39m\\\\n \\\\u001b[8mhidden\\\\u001b[28m\\\\n \\\\u001b[7minverse\\\\u001b[27m\\\\n \\\\u001b[3mitalic\\\\u001b[23m\\\\n \\\\u001b[35mmagenta\\\\u001b[39m\\\\n \\\\u001b[95mmagentaBright\\\\u001b[39m\\\\n \\\\u001b[31mred\\\\u001b[39m\\\\n \\\\u001b[91mredBright\\\\u001b[39m\\\\n \\\\u001b[0mreset\\\\u001b[0m\\\\n \\\\u001b[9mstrikethrough\\\\u001b[29m\\\\n \\\\u001b[4munderline\\\\u001b[24m\\\\n \\\\u001b[37mwhite\\\\u001b[39m\\\\n \\\\u001b[97mwhiteBright\\\\u001b[39m\\\\n \\\\u001b[33myellow\\\\u001b[39m\\\\n \\\\u001b[93myellowBright\\\\u001b[39m\\\\n \\"]"',
'"[\\"\\\\u001b[104m tool name \\\\u001b[49m with all colors: \\\\n \\\\u001b[40mbgBlack\\\\u001b[49m\\\\n \\\\u001b[100mbgBlackBright\\\\u001b[49m\\\\n \\\\u001b[44mbgBlue\\\\u001b[49m\\\\n \\\\u001b[104mbgBlueBright\\\\u001b[49m\\\\n \\\\u001b[46mbgCyan\\\\u001b[49m\\\\n \\\\u001b[106mbgCyanBright\\\\u001b[49m\\\\n \\\\u001b[42mbgGreen\\\\u001b[49m\\\\n \\\\u001b[102mbgGreenBright\\\\u001b[49m\\\\n \\\\u001b[45mbgMagenta\\\\u001b[49m\\\\n \\\\u001b[105mbgMagentaBright\\\\u001b[49m\\\\n \\\\u001b[41mbgRed\\\\u001b[49m\\\\n \\\\u001b[101mbgRedBright\\\\u001b[49m\\\\n \\\\u001b[47mbgWhite\\\\u001b[49m\\\\n \\\\u001b[107mbgWhiteBright\\\\u001b[49m\\\\n \\\\u001b[43mbgYellow\\\\u001b[49m\\\\n \\\\u001b[103mbgYellowBright\\\\u001b[49m\\\\n \\\\u001b[30mblack\\\\u001b[39m\\\\n \\\\u001b[90mblackBright\\\\u001b[39m\\\\n \\\\u001b[34mblue\\\\u001b[39m\\\\n \\\\u001b[94mblueBright\\\\u001b[39m\\\\n \\\\u001b[1mbold\\\\u001b[22m\\\\n \\\\u001b[36mcyan\\\\u001b[39m\\\\n \\\\u001b[96mcyanBright\\\\u001b[39m\\\\n \\\\u001b[2mdim\\\\u001b[22m\\\\n \\\\u001b[90mgray\\\\u001b[39m\\\\n \\\\u001b[32mgreen\\\\u001b[39m\\\\n \\\\u001b[92mgreenBright\\\\u001b[39m\\\\n \\\\u001b[8mhidden\\\\u001b[28m\\\\n \\\\u001b[7minverse\\\\u001b[27m\\\\n \\\\u001b[3mitalic\\\\u001b[23m\\\\n \\\\u001b[35mmagenta\\\\u001b[39m\\\\n \\\\u001b[95mmagentaBright\\\\u001b[39m\\\\n \\\\u001b[31mred\\\\u001b[39m\\\\n \\\\u001b[91mredBright\\\\u001b[39m\\\\n \\\\u001b[0mreset\\\\u001b[0m\\\\n \\\\u001b[9mstrikethrough\\\\u001b[29m\\\\n \\\\u001b[4munderline\\\\u001b[24m\\\\n \\\\u001b[37mwhite\\\\u001b[39m\\\\n \\\\u001b[97mwhiteBright\\\\u001b[39m\\\\n \\\\u001b[33myellow\\\\u001b[39m\\\\n \\\\u001b[93myellowBright\\\\u001b[39m\\\\n \\"]"',
)
})

Expand Down Expand Up @@ -206,7 +206,7 @@ describe('kitql - helper - Log', () => {
expect(spy).toHaveBeenCalledOnce()

expect(stry0(result)).toMatchInlineSnapshot(
'"[\\"\\\\u001b[106m tool name \\\\u001b[49m with red: \\\\u001b[31mred\\\\u001b[39m and another \\\\u001b[31mred2\\\\u001b[39m\\"]"',
'"[\\"\\\\u001b[104m tool name \\\\u001b[49m with red: \\\\u001b[31mred\\\\u001b[39m and another \\\\u001b[31mred2\\\\u001b[39m\\"]"',
)
})
})
Loading

0 comments on commit 2aaacce

Please sign in to comment.