Skip to content

Commit 33678a6

Browse files
authored
Merge pull request #13 from 20minutes/fix/biome
Use Biome instead of ESLint
2 parents 17cc248 + f546607 commit 33678a6

24 files changed

+191
-1822
lines changed

.swcrc.cjs renamed to .cjs.swcrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://swc.rs/schema.json",
23
"jsc": {
34
"target": "es2022",
45
"parser": {

.swcrc.esm renamed to .esm.swcrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://swc.rs/schema.json",
23
"jsc": {
34
"target": "es2022",
45
"parser": {

biome.jsonc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": ["@20minutes/eslint-config/biome"],
3+
"javascript": {
4+
"jsxRuntime": "reactClassic"
5+
},
6+
"linter": {
7+
"rules": {
8+
"a11y": "off"
9+
}
10+
}
11+
}

eslint.config.mjs

Lines changed: 0 additions & 45 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
"repository": "20minutes/draft-convert",
1717
"scripts": {
1818
"build": "yarn clean && yarn build:esm && yarn build:cjs && yarn build:types",
19-
"build:cjs": "swc src -d dist --config-file .swcrc.cjs --strip-leading-paths && node scripts/rename-dist-cjs-entry.js",
20-
"build:esm": "swc src -d dist --config-file .swcrc.esm --strip-leading-paths --delete-dir-on-start --out-file-extension mjs && node scripts/fix-dist-esm-imports.js",
19+
"build:cjs": "swc src -d dist --config-file .cjs.swcrc --strip-leading-paths && node scripts/rename-dist-cjs-entry.js",
20+
"build:esm": "swc src -d dist --config-file .esm.swcrc --strip-leading-paths --delete-dir-on-start --out-file-extension mjs && node scripts/fix-dist-esm-imports.js",
2121
"build:types": "node scripts/build-dist-types.js",
2222
"test": "jest",
2323
"test:watch": "jest --watch",
2424
"clean": "rimraf ./dist ./lib ./esm",
2525
"build-and-test": "yarn clean && yarn test",
26-
"lint": "eslint src/ test/"
26+
"lint": "biome check --max-diagnostics=none",
27+
"lint:fix": "biome check --write --unsafe --max-diagnostics=none"
2728
},
2829
"files": [
2930
"dist"
@@ -49,17 +50,11 @@
4950
"invariant": "^2.2.1"
5051
},
5152
"devDependencies": {
52-
"@20minutes/eslint-config": "^2.0.0",
53+
"@20minutes/eslint-config": "^3.0.0",
5354
"@swc/cli": "^0.8.0",
5455
"@swc/core": "^1.9.2",
5556
"@swc/jest": "^0.2.36",
5657
"draft-js": "^0.11.7",
57-
"eslint": "^9.0.0",
58-
"eslint-config-prettier": "^10.1.8",
59-
"eslint-plugin-import": "^2.32.0",
60-
"eslint-plugin-prettier": "^5.5.4",
61-
"eslint-plugin-react": "7.37.5",
62-
"eslint-plugin-react-hooks": "^7.0.1",
6358
"jest": "^30.2.0",
6459
"jest-environment-jsdom": "^30.2.0",
6560
"prettier": "^3.6.2",

scripts/fix-dist-esm-imports.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,15 @@ const rewriteSpecifiers = (source) =>
2020
source
2121
.replace(
2222
/(\bfrom\s+['"])(\.\.?\/[^'"]+)(['"])/g,
23-
(full, before, specifier, after) =>
24-
`${before}${toMjsSpecifier(specifier)}${after}`
23+
(_full, before, specifier, after) => `${before}${toMjsSpecifier(specifier)}${after}`
2524
)
2625
.replace(
2726
/(\bimport\s*['"])(\.\.?\/[^'"]+)(['"])/g,
28-
(full, before, specifier, after) =>
29-
`${before}${toMjsSpecifier(specifier)}${after}`
27+
(_full, before, specifier, after) => `${before}${toMjsSpecifier(specifier)}${after}`
3028
)
3129
.replace(
3230
/(\bimport\s*\(\s*['"])(\.\.?\/[^'"]+)(['"]\s*\))/g,
33-
(full, before, specifier, after) =>
34-
`${before}${toMjsSpecifier(specifier)}${after}`
31+
(_full, before, specifier, after) => `${before}${toMjsSpecifier(specifier)}${after}`
3532
)
3633

3734
const walkFiles = (directory) =>

src/blockEntities.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import updateMutation from './util/updateMutation.js'
2-
import rangeSort from './util/rangeSort.js'
31
import getElementHTML from './util/getElementHTML.js'
42
import getElementTagLength from './util/getElementTagLength.js'
3+
import rangeSort from './util/rangeSort.js'
4+
import updateMutation from './util/updateMutation.js'
55

6-
const converter = (entity = {}, originalText = '') => originalText
6+
const converter = (_entity = {}, originalText = '') => originalText
77

88
export default (block, entityMap, entityConverter = converter) => {
99
let resultText = [...block.text]
@@ -14,10 +14,7 @@ export default (block, entityMap, entityConverter = converter) => {
1414
getEntityHTML = entityConverter(converter)
1515
}
1616

17-
if (
18-
Object.prototype.hasOwnProperty.call(block, 'entityRanges') &&
19-
block.entityRanges.length > 0
20-
) {
17+
if (Object.hasOwn(block, 'entityRanges') && block.entityRanges.length > 0) {
2118
let entities = block.entityRanges.sort(rangeSort)
2219

2320
let styles = block.inlineStyleRanges
@@ -43,7 +40,7 @@ export default (block, entityMap, entityConverter = converter) => {
4340
const suffixLength = getElementTagLength(entityHTML, 'end')
4441

4542
const updateLaterMutation = (mutation, mutationIndex) => {
46-
if (mutationIndex > index || Object.prototype.hasOwnProperty.call(mutation, 'style')) {
43+
if (mutationIndex > index || Object.hasOwn(mutation, 'style')) {
4744
return updateMutation(
4845
mutation,
4946
entityRange.offset,

src/blockInlineStyles.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import invariant from 'invariant'
2-
import styleObjectFunction from './util/styleObjectFunction.js'
2+
import defaultInlineHTML from './default/defaultInlineHTML.js'
33
import accumulateFunction from './util/accumulateFunction.js'
44
import getElementHTML from './util/getElementHTML.js'
55
import rangeSort from './util/rangeSort.js'
6-
import defaultInlineHTML from './default/defaultInlineHTML.js'
6+
import styleObjectFunction from './util/styleObjectFunction.js'
77

88
const subtractStyles = (original, toRemove) =>
99
original.filter((el) => !toRemove.some((elToRemove) => elToRemove.style === el.style))

src/convertFromHTML.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@
1010
* of patent rights can be found in the PATENTS file in the same directory.
1111
*/
1212

13-
// immutable is CJS-only; default import maps to module.exports for Node ESM interop.
14-
// eslint-disable-next-line import/default
15-
import Immutable from 'immutable'
1613
import DraftJS from 'draft-js'
14+
import Immutable from 'immutable'
1715
import getSafeBodyFromHTML from './util/parseHTML.js'
1816
import rangeSort from './util/rangeSort.js'
1917

20-
// eslint-disable-next-line import/no-named-as-default-member
21-
const { List, Map, OrderedSet } = Immutable
2218
const {
2319
BlockMapBuilder,
2420
CharacterMetadata,
@@ -63,13 +59,13 @@ const handleMiddleware = (maybeMiddleware, base) => {
6359
return maybeMiddleware
6460
}
6561

66-
const defaultHTMLToBlock = (nodeName, node, lastList) => undefined
62+
const defaultHTMLToBlock = (_nodeName, _node, _lastList) => undefined
6763

68-
const defaultHTMLToStyle = (nodeName, node, currentStyle) => currentStyle
64+
const defaultHTMLToStyle = (_nodeName, _node, currentStyle) => currentStyle
6965

70-
const defaultHTMLToEntity = (nodeName, node) => undefined
66+
const defaultHTMLToEntity = (_nodeName, _node) => undefined
7167

72-
const defaultTextToEntity = (text) => []
68+
const defaultTextToEntity = (_text) => []
7369

7470
const nullthrows = (x) => {
7571
if (x != null) {
@@ -97,17 +93,17 @@ function getWhitespaceChunk(inEntity) {
9793

9894
return {
9995
text: SPACE,
100-
inlines: [OrderedSet()],
96+
inlines: [Immutable.OrderedSet()],
10197
entities,
10298
blocks: [],
10399
}
104100
}
105101

106-
function getSoftNewlineChunk(block, depth, flat = false, data = Map()) {
102+
function getSoftNewlineChunk(block, depth, flat = false, data = Immutable.Map()) {
107103
if (flat === true) {
108104
return {
109105
text: '\r',
110-
inlines: [OrderedSet()],
106+
inlines: [Immutable.OrderedSet()],
111107
entities: new Array(1),
112108
blocks: [
113109
{
@@ -122,16 +118,16 @@ function getSoftNewlineChunk(block, depth, flat = false, data = Map()) {
122118

123119
return {
124120
text: '\n',
125-
inlines: [OrderedSet()],
121+
inlines: [Immutable.OrderedSet()],
126122
entities: new Array(1),
127123
blocks: [],
128124
}
129125
}
130126

131-
function getBlockDividerChunk(block, depth, data = Map()) {
127+
function getBlockDividerChunk(block, depth, data = Immutable.Map()) {
132128
return {
133129
text: '\r',
134-
inlines: [OrderedSet()],
130+
inlines: [Immutable.OrderedSet()],
135131
entities: new Array(1),
136132
blocks: [
137133
{
@@ -175,7 +171,7 @@ function getBlockTypeForTag(tag, lastList) {
175171
}
176172
}
177173

178-
function baseCheckBlockType(nodeName, node, lastList) {
174+
function baseCheckBlockType(nodeName, _node, lastList) {
179175
return getBlockTypeForTag(nodeName, lastList)
180176
}
181177

@@ -209,7 +205,7 @@ function processInlineTag(tag, node, currentStyle) {
209205
return currentStyle
210206
}
211207

212-
function baseProcessInlineTag(tag, node, inlineStyles = OrderedSet()) {
208+
function baseProcessInlineTag(tag, node, inlineStyles = Immutable.OrderedSet()) {
213209
return processInlineTag(tag, node, inlineStyles)
214210
}
215211

@@ -376,10 +372,10 @@ function genFragment(
376372

377373
if (typeof blockInfo === 'string') {
378374
blockType = blockInfo
379-
blockDataMap = Map()
375+
blockDataMap = Immutable.Map()
380376
} else {
381377
blockType = typeof blockInfo === 'string' ? blockInfo : blockInfo.type
382-
blockDataMap = blockInfo.data ? Map(blockInfo.data) : Map()
378+
blockDataMap = blockInfo.data ? Immutable.Map(blockInfo.data) : Immutable.Map()
383379
}
384380
if (!inBlock && (fragmentBlockTags.indexOf(nodeName) !== -1 || blockType)) {
385381
chunk = getBlockDividerChunk(
@@ -472,10 +468,10 @@ function genFragment(
472468

473469
if (typeof newBlockInfo === 'string') {
474470
newBlockType = newBlockInfo
475-
newBlockData = Map()
471+
newBlockData = Immutable.Map()
476472
} else {
477473
newBlockType = newBlockInfo.type || getBlockTypeForTag(nodeName, lastList)
478-
newBlockData = newBlockInfo.data ? Map(newBlockInfo.data) : Map()
474+
newBlockData = newBlockInfo.data ? Immutable.Map(newBlockInfo.data) : Immutable.Map()
479475
}
480476

481477
chunk = joinChunks(
@@ -492,7 +488,11 @@ function genFragment(
492488
}
493489

494490
if (newBlock) {
495-
chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, Map()), options.flat)
491+
chunk = joinChunks(
492+
chunk,
493+
getBlockDividerChunk(nextBlockType, depth, Immutable.Map()),
494+
options.flat
495+
)
496496
}
497497

498498
return chunk
@@ -527,7 +527,7 @@ function getChunkForHTML(
527527
// UL block to sta rt with.
528528
let chunk = genFragment(
529529
safeBody,
530-
OrderedSet(),
530+
Immutable.OrderedSet(),
531531
'ul',
532532
null,
533533
workingBlocks,
@@ -563,14 +563,14 @@ function getChunkForHTML(
563563

564564
// If we saw no block tags, put an unstyled one in
565565
if (chunk.blocks.length === 0) {
566-
chunk.blocks.push({ type: 'unstyled', data: Map(), depth: 0 })
566+
chunk.blocks.push({ type: 'unstyled', data: Immutable.Map(), depth: 0 })
567567
}
568568

569569
// Sometimes we start with text that isn't in a block, which is then
570570
// followed by blocks. Need to fix up the blocks to add in
571571
// an unstyled block for this content
572572
if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
573-
chunk.blocks.unshift({ type: 'unstyled', data: Map(), depth: 0 })
573+
chunk.blocks.unshift({ type: 'unstyled', data: Immutable.Map(), depth: 0 })
574574
}
575575

576576
return chunk
@@ -619,7 +619,7 @@ function convertFromHTMLtoContentBlocks(
619619
const end = start + textBlock.length
620620
const inlines = nullthrows(chunk).inlines.slice(start, end)
621621
const entities = nullthrows(chunk).entities.slice(start, end)
622-
const characterList = List(
622+
const characterList = Immutable.List(
623623
inlines.map((style, entityIndex) => {
624624
const data = { style, entity: null }
625625
if (entities[entityIndex]) {

src/convertToHTML.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1+
import DraftJS from 'draft-js'
12
import invariant from 'invariant'
23
import React from 'react'
34
import ReactDOMServer from 'react-dom/server'
4-
import DraftJS from 'draft-js'
5-
import encodeBlock from './encodeBlock.js'
65
import blockEntities from './blockEntities.js'
76
import blockInlineStyles from './blockInlineStyles.js'
7+
import defaultBlockHTML from './default/defaultBlockHTML.js'
8+
import encodeBlock from './encodeBlock.js'
89
import accumulateFunction from './util/accumulateFunction.js'
910
import blockTypeObjectFunction from './util/blockTypeObjectFunction.js'
1011
import getBlockTags from './util/getBlockTags.js'
1112
import getNestedBlockTags from './util/getNestedBlockTags.js'
12-
import defaultBlockHTML from './default/defaultBlockHTML.js'
1313

1414
const { convertToRaw } = DraftJS
1515

16-
const defaultEntityToHTML = (entity, originalText) => originalText
17-
const defaultValidateHTML = (html) => true
16+
const defaultEntityToHTML = (_entity, originalText) => originalText
17+
const defaultValidateHTML = (_html) => true
1818

1919
const convertToHTML =
2020
({
@@ -99,7 +99,7 @@ const convertToHTML =
9999
html = blockHTML.start + innerHTML + blockHTML.end
100100
}
101101

102-
if (innerHTML.length === 0 && Object.prototype.hasOwnProperty.call(blockHTML, 'empty')) {
102+
if (innerHTML.length === 0 && Object.hasOwn(blockHTML, 'empty')) {
103103
if (React.isValidElement(blockHTML.empty)) {
104104
html = ReactDOMServer.renderToStaticMarkup(blockHTML.empty)
105105
} else {
@@ -127,11 +127,7 @@ const convertToHTML =
127127
}
128128

129129
export default (...args) => {
130-
if (
131-
args.length === 1 &&
132-
Object.prototype.hasOwnProperty.call(args[0], '_map') &&
133-
args[0].getBlockMap != null
134-
) {
130+
if (args.length === 1 && Object.hasOwn(args[0], '_map') && args[0].getBlockMap != null) {
135131
// skip higher-order function and use defaults
136132
return convertToHTML({})(...args)
137133
}

0 commit comments

Comments
 (0)