Skip to content

Commit

Permalink
Bye ESLint+Prettier, welcome Biome
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr committed Jul 10, 2024
1 parent 00f8438 commit 6d305d2
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 192 deletions.
62 changes: 0 additions & 62 deletions .eslintrc

This file was deleted.

9 changes: 0 additions & 9 deletions .prettierrc

This file was deleted.

42 changes: 42 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 4,
"lineEnding": "lf",
"lineWidth": 100,
"attributePosition": "auto"
},
"files": {
"ignore": ["dist"]
},
"organizeImports": { "enabled": true },
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noNonNullAssertion": "off",
"noParameterAssign": "off",
"noUselessElse": "off",
"useNumberNamespace": "off"
}
}
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "always",
"arrowParentheses": "always",
"bracketSpacing": true,
"bracketSameLine": false,
"quoteStyle": "double",
"attributePosition": "auto"
}
},
"overrides": [{ "include": ["tests/perf/benchmark/*"], "linter": { "enabled": false } }]
}
26 changes: 5 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"scripts": {
"build": "tsup",
"lint": "eslint mod.ts src/*.ts tests/*/*.ts",
"lint": "biome check",
"prepublish": "yarn build",
"test": "jest"
},
Expand All @@ -22,38 +22,22 @@
"type": "git",
"url": "https://github.com/arendjr/text-clipper.git"
},
"files": [
"dist"
],
"keywords": [
"clip",
"html",
"string",
"text",
"trim",
"truncate"
],
"files": ["dist"],
"keywords": ["clip", "html", "string", "text", "trim", "truncate"],
"license": "MIT",
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@tsconfig/node18": "^18.2.2",
"@types/jest": "^25.2.2",
"@typescript-eslint/eslint-plugin": "^2.33.0",
"@typescript-eslint/parser": "^2.33.0",
"eslint": "^6.0.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-jest": "^23.11.0",
"eslint-plugin-prettier": "^3.1.3",
"jest": "^25.0.0",
"prepush": "^3.1.11",
"prettier": "^2.0.5",
"ts-jest": "^25.5.1",
"tsup": "^7.2.0",
"typescript": "^5.2.2"
},
"prepush": {
"tasks": [
"yarn lint",
"yarn test"
]
"tasks": ["yarn lint", "yarn test"]
}
}
23 changes: 13 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ function clipHtml(string: string, maxLength: number, options: ClipHtmlOptions):

const tagStack: Array<string> = []; // Stack of currently open HTML tags.
const popTagStack = (result: string) => {
let tagName;
let tagName: string | undefined;
// biome-ignore lint/style/noCommaOperator: Otherwise we need to pop...
// biome-ignore lint/suspicious/noAssignInExpressions: ... in two places.
while (((tagName = tagStack.pop()), tagName !== undefined)) {
if (!shouldStrip(tagName)) {
result += `</${tagName}>`;
Expand Down Expand Up @@ -623,15 +625,16 @@ function isCharacterReferenceCharacter(charCode: number): boolean {
}

function isLineBreak(string: string, index: number): boolean {
const firstCharCode = string.charCodeAt(index);
if (firstCharCode === NEWLINE_CHAR_CODE) {
return true;
} else if (firstCharCode === TAG_OPEN_CHAR_CODE) {
const newlineElements = `(${BLOCK_ELEMENTS.join("|")}|br)`;
const newlineRegExp = new RegExp(`^<${newlineElements}[\t\n\f\r ]*/?>`, "i");
return newlineRegExp.test(string.slice(index));
} else {
return false;
switch (string.charCodeAt(index)) {
case NEWLINE_CHAR_CODE:
return true;
case TAG_OPEN_CHAR_CODE: {
const newlineElements = `(${BLOCK_ELEMENTS.join("|")}|br)`;
const newlineRegExp = new RegExp(`^<${newlineElements}[\t\n\f\r ]*/?>`, "i");
return newlineRegExp.test(string.slice(index));
}
default:
return false;
}
}

Expand Down
1 change: 0 additions & 1 deletion tests/perf/.eslintignore

This file was deleted.

Loading

0 comments on commit 6d305d2

Please sign in to comment.