Skip to content

Commit

Permalink
chore(lint): add certain unicorn eslint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Apr 15, 2024
1 parent 447067f commit 082c8ca
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const config = {
'prettier',
'react',
'tsdoc',
'unicorn',
],
ignorePatterns: [
'**/etc/*',
Expand Down Expand Up @@ -182,6 +183,10 @@ const config = {
'no-unused-vars': 'off',
'no-useless-catch': 'warn',
'no-async-promise-executor': 'warn',
'unicorn/prefer-string-slice': 'error',
'unicorn/prefer-node-protocol': 'error',
'unicorn/prefer-keyboard-event-key': 'error',
'unicorn/custom-error-definition': 'error',
},
settings: {
'import/extensions': extensions,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-simple-import-sort": "^12.0.0",
"eslint-plugin-tsdoc": "^0.2.17",
"eslint-plugin-unicorn": "^52.0.0",
"eslint-plugin-unused-imports": "^3.1.0",
"execa": "^2.0.0",
"glob": "^7.2.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/@sanity/block-tools/src/HtmlDeserializer/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,18 @@ export function trimWhitespace(blocks: TypedObject[]): TypedObject[] {
child.text = child.text.replace(/[^\S\n]+$/g, '')
}
if (
/\s/.test(child.text.substring(child.text.length - 1)) &&
/\s/.test(child.text.slice(Math.max(0, child.text.length - 1))) &&
nextChild &&
isMinimalSpan(nextChild) &&
/\s/.test(nextChild.text.substring(0, 1))
/\s/.test(nextChild.text.slice(0, 1))
) {
child.text = child.text.replace(/[^\S\n]+$/g, '')
}
if (
/\s/.test(child.text.substring(0, 1)) &&
/\s/.test(child.text.slice(0, 1)) &&
prevChild &&
isMinimalSpan(prevChild) &&
/\s/.test(prevChild.text.substring(prevChild.text.length - 1))
/\s/.test(prevChild.text.slice(Math.max(0, prevChild.text.length - 1)))
) {
child.text = child.text.replace(/^[^\S\n]+/g, '')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/block-tools/src/util/randomKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function whatwgRNG(length = 16) {

const byteToHex: string[] = []
for (let i = 0; i < 256; ++i) {
byteToHex[i] = (i + 0x100).toString(16).substring(1)
byteToHex[i] = (i + 0x100).toString(16).slice(1)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as fs from 'node:fs'
import * as path from 'node:path'
import assert from 'node:assert'
import fs from 'node:fs'
import path from 'node:path'

import {describe, it} from '@jest/globals'
import * as assert from 'assert'
import {JSDOM} from 'jsdom'

import * as blockTools from '../../../src'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from 'node:assert'

import {describe, it} from '@jest/globals'
import * as assert from 'assert'

import {normalizeBlock} from '../../../src/util/normalizeBlock'

Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/schema/example/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'assert'
import assert from 'node:assert'

import {Schema} from '../src/legacy/Schema'
import schemaDef from './schema-def'
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/util/src/content/randomKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const getByteHexTable = (() => {

table = []
for (let i = 0; i < 256; ++i) {
table[i] = (i + 0x100).toString(16).substring(1)
table[i] = (i + 0x100).toString(16).slice(1)
}
return table
}
Expand Down
65 changes: 65 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 082c8ca

Please sign in to comment.