Skip to content

Commit

Permalink
Merge pull request #26 from nemuvski/use-biome
Browse files Browse the repository at this point in the history
Biomeの導入, 導入に伴い警告箇所を修正
  • Loading branch information
nemuvski authored Jan 31, 2024
2 parents 42a3694 + 6f0d4cc commit fd1c5e2
Show file tree
Hide file tree
Showing 36 changed files with 265 additions and 929 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ node_modules/

# Editor/IDE
.idea/
.vscode/
#.vscode/

# Logs
*.log
Expand Down
5 changes: 0 additions & 5 deletions .prettierignore

This file was deleted.

11 changes: 0 additions & 11 deletions .prettierrc.js

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["biomejs.biome"]
}
20 changes: 20 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[javascriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
},
"editor.codeActionsOnSave": {
"quickfix.biome": "explicit",
"source.organizeImports.biome": "explicit"
}
}
83 changes: 83 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"ignore": [
".turbo/**",
".idea/**",
".coverage/**",
"packages/**/dist/**",
"website/.docusaurus/**",
"website/.typedoc/**",
"website/build/**"
],
"rules": {
"recommended": true,
"correctness": {
"useExhaustiveDependencies": "warn",
"noUnusedVariables": "warn"
},
"style": {
"noDefaultExport": "off",
"noUnusedTemplateLiteral": "off"
},
"nursery": {
"useExportType": "error",
"useImportType": "error",
"noUnusedImports": "warn",
"noGlobalEval": "error",
"noGlobalAssign": "error",
"useNodejsImportProtocol": "warn"
}
}
},
"formatter": {
"enabled": true,
"ignore": [
".turbo/",
".idea/**",
".coverage/**",
"packages/**/dist/**",
"website/.docusaurus/**",
"website/.typedoc/**",
"website/build/**"
],
"lineEnding": "lf",
"lineWidth": 120,
"indentStyle": "space",
"indentWidth": 2
},
"javascript": {
"formatter": {
"trailingComma": "es5",
"quoteStyle": "single",
"semicolons": "asNeeded",
"jsxQuoteStyle": "single",
"arrowParentheses": "always"
}
},
"overrides": [
{
"include": [".vscode/**"],
"json": {
"parser": {
"allowComments": true,
"allowTrailingCommas": true
}
}
},
{
"include": ["website/**"],
"linter": {
"rules": {
"suspicious": {
"noArrayIndexKey": "off"
}
}
}
}
]
}
48 changes: 0 additions & 48 deletions local/eslint-config-custom/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions local/eslint-config-custom/package.json

This file was deleted.

16 changes: 5 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,25 @@
"local/*"
],
"scripts": {
"lint": "turbo run lint",
"format": "prettier --check './**/*.{js,jsx,ts,tsx}'",
"format:fix": "prettier --write './**/*.{js,jsx,ts,tsx}'",
"lint": "biome lint ./",
"lint:fix": "biome lint --apply ./",
"format": "biome format ./",
"format:fix": "biome format --write ./",
"typecheck": "turbo run typecheck",
"test": "turbo run test",
"build": "turbo run build --filter=./packages/*",
"docs": "npm run build -w website"
},
"devDependencies": {
"@local/eslint-config-custom": "workspace:*",
"@biomejs/biome": "1.5.3",
"@local/tsconfig": "workspace:*",
"@testing-library/react": "^14.1.2",
"@types/node": "^20.5.7",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"@vitejs/plugin-react": "^4.2.1",
"@vitest/coverage-v8": "^1.1.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-regexp": "^2.1.2",
"jsdom": "^23.0.1",
"prettier": "^3.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rimraf": "^5.0.1",
Expand Down
5 changes: 0 additions & 5 deletions packages/react/.eslintrc.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/react/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
.turbo/
src/
tests/
.eslintrc.js
tsconfig.json
vitest.config.ts
6 changes: 3 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"lint": "eslint --ext .js,.jsx,.ts,.tsx .",
"lint:fix": "eslint --fix --ext .js,.jsx,.ts,.tsx .",
"typecheck": "tsc --noEmit",
"test": "vitest --run --coverage",
"build": "tsup src/ --format=esm,cjs --dts"
Expand All @@ -44,7 +42,9 @@
"react": "^18.0.0"
},
"tsup": {
"entry": ["src/index.ts"],
"entry": [
"src/index.ts"
],
"splitting": false,
"sourcemap": false,
"minify": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Either.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RC } from '../types/rc'
import type { RC } from '../types/rc'

/**
* 条件式がtrue/falseで出力する内容を切り替えるコンポーネント
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Maybe.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RC } from '../types/rc'
import type { RC } from '../types/rc'

/**
* 条件式がtrueになった場合のみ子要素を出力するコンポーネント
Expand Down
5 changes: 0 additions & 5 deletions packages/utils/.eslintrc.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/utils/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
.turbo/
src/
tests/
.eslintrc.js
tsconfig.json
vitest.config.ts
6 changes: 3 additions & 3 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"lint": "eslint --ext .js,.jsx,.ts,.tsx .",
"lint:fix": "eslint --fix --ext .js,.jsx,.ts,.tsx .",
"typecheck": "tsc --noEmit",
"test": "vitest --run --coverage",
"build": "tsup src/ --format=esm,cjs --dts"
},
"tsup": {
"entry": ["src/index.ts"],
"entry": [
"src/index.ts"
],
"splitting": false,
"sourcemap": false,
"minify": true,
Expand Down
3 changes: 1 addition & 2 deletions packages/utils/src/functions/buildPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ export function buildPath(...paths: Array<string | number | null | undefined>) {
if (isString(p)) {
if (i === 0) {
return p.trim().replace(/\/*$/g, '')
} else {
return p.trim().replace(/(^\/*|\/*$)/g, '')
}
return p.trim().replace(/(^\/*|\/*$)/g, '')
}
// フォールバック
return p
Expand Down
8 changes: 4 additions & 4 deletions packages/utils/src/functions/cls.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isNullish } from './isNullish'
import { isBoolean } from './isBoolean'
import { isString } from './isString'
import { isNullish } from './isNullish'
import { isNumber } from './isNumber'
import { isString } from './isString'

/**
* cls()の引数optionsの型
Expand Down Expand Up @@ -58,10 +58,10 @@ export function cls(
if (isString(value) || isNumber(value)) return options?.trimPeriod ? String(value).replace(/\.+/g, '') : String(value)
let res = ''
if (Array.isArray(value)) {
value.forEach((n) => {
for (const n of value) {
const childRes = cls(n, options)
if (childRes) res += (res && ' ') + childRes
})
}
} else {
for (const key in value) {
if (value[key]) res += (res && ' ') + key
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/src/functions/containParamInUrl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isString } from './isString'
import { escapeRegExpChars } from './escapeRegExpChars'
import { getQueryString } from './getQueryString'
import { isString } from './isString'
import { isURL } from './isURL'
import { escapeRegExpChars } from './escapeRegExpChars'

/**
* 引数urlで指定したパラメータ名が存在する場合はTrueを返却
Expand All @@ -25,7 +25,7 @@ import { escapeRegExpChars } from './escapeRegExpChars'
*/
export function containParamInUrl<P extends string>(url: string | URL | URLSearchParams, paramName: P) {
if (isString(url)) {
return new RegExp('(\\?|&)' + escapeRegExpChars(paramName) + '=', 'g').test(getQueryString(url))
return new RegExp(`(\\?|&)${escapeRegExpChars(paramName)}=`, 'g').test(getQueryString(url))
}
return isURL(url) ? url.searchParams.has(paramName) : url.has(paramName)
}
33 changes: 17 additions & 16 deletions packages/utils/src/functions/diffArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,25 @@ export function diffArray<T>(

if (!left.length) {
return { leftOnlyItems, rightOnlyItems: right, bothItems }
} else if (!right.length) {
}
if (!right.length) {
return { leftOnlyItems: left, rightOnlyItems, bothItems }
} else {
// 配列leftを起点に配列leftにしか無い要素、両方に存在する要素を評価する
for (const leftItem of left) {
const matchedIndex = right.findIndex((rightItem) => matchFn(leftItem, rightItem))
if (matchedIndex < 0) {
leftOnlyItems.push(leftItem)
} else {
bothItems.push(leftItem)
}
}

// 配列leftを起点に配列leftにしか無い要素、両方に存在する要素を評価する
for (const leftItem of left) {
const matchedIndex = right.findIndex((rightItem) => matchFn(leftItem, rightItem))
if (matchedIndex < 0) {
leftOnlyItems.push(leftItem)
} else {
bothItems.push(leftItem)
}
// 次に、配列rightから両方に存在する要素を除いたものを求める
for (const rightItem of right) {
const matchedIndex = bothItems.findIndex((bothItem) => matchFn(rightItem, bothItem))
if (matchedIndex < 0) {
rightOnlyItems.push(rightItem)
}
}
// 次に、配列rightから両方に存在する要素を除いたものを求める
for (const rightItem of right) {
const matchedIndex = bothItems.findIndex((bothItem) => matchFn(rightItem, bothItem))
if (matchedIndex < 0) {
rightOnlyItems.push(rightItem)
}
}
return { leftOnlyItems, rightOnlyItems, bothItems }
Expand Down
Loading

0 comments on commit fd1c5e2

Please sign in to comment.