Skip to content

Commit 9bbb858

Browse files
committed
chore: switch from ESLint to Biome
1 parent 90fcfcc commit 9bbb858

16 files changed

+887
-2813
lines changed

.eslintrc.js

-24
This file was deleted.

.vscode/extensions.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["biomejs.biome"]
3+
}

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"editor.defaultFormatter": "biomejs.biome"
3+
}

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ See the [contribution guidelines](CONTRIBUTING.md).
138138

139139
## Tests
140140

141-
We use [Jest](https://jestjs.io/) for running our tests. The test suite can be run by running `npm run test`. This will run both Jest and ESLint.
141+
We use [Jest](https://jestjs.io/) for running our tests. The test suite can be run by running `npm run test`. This will run both Jest and Biome.
142142

143143
## Code style
144144

145-
We use [ESLint](https://eslint.org/) for making sure that our code remains pretty and consistent throughout the project. If your editor doesn't automatically pick up our config you can lint the code using `npm run lint`.
145+
We use [Biome](https://biomejs.dev/) for making sure that our code remains pretty and consistent throughout the project. If your editor doesn't automatically pick up our config you can lint the code using `npm run lint`.
146146

147147
## A note on Dependabot
148148

biome.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
3+
"organizeImports": {
4+
"enabled": true
5+
},
6+
"linter": {
7+
"enabled": true,
8+
"rules": {
9+
"recommended": true
10+
}
11+
},
12+
"formatter": {
13+
"indentStyle": "space"
14+
},
15+
"javascript": {
16+
"formatter": {
17+
"quoteStyle": "single",
18+
"trailingCommas": "none"
19+
}
20+
},
21+
"overrides": [
22+
{
23+
"include": ["test/debug.js"],
24+
"formatter": {
25+
"lineWidth": 320
26+
}
27+
}
28+
]
29+
}

commitlint.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ module.exports = {
55
'subject-case': [1, 'always', 'lower-case'],
66
'header-case': [1, 'always', 'lower-case']
77
}
8-
}
8+
};

lib/escapeHtml.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,25 @@ const charCodeMap = {
3535
39: ''', // '
3636
60: '&lt;', // <
3737
62: '&gt;' // >
38-
}
38+
};
3939

40-
function escapeHtml (str) {
41-
let html = ''
42-
let lastIndex = 0
40+
function escapeHtml(str) {
41+
let html = '';
42+
let lastIndex = 0;
4343

4444
for (let i = 0; i < str.length; i++) {
45-
const escape = charCodeMap[str.charCodeAt(i)]
46-
if (!escape) continue
45+
const replacement = charCodeMap[str.charCodeAt(i)];
46+
if (!replacement) continue;
4747

4848
if (lastIndex !== i) {
49-
html += str.substring(lastIndex, i)
49+
html += str.substring(lastIndex, i);
5050
}
5151

52-
lastIndex = i + 1
53-
html += escape
52+
lastIndex = i + 1;
53+
html += replacement;
5454
}
5555

56-
return html + str.substring(lastIndex)
56+
return html + str.substring(lastIndex);
5757
}
5858

59-
module.exports = escapeHtml
59+
module.exports = escapeHtml;

lib/index.d.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
declare module 'sql-highlight' {
22
export interface HighlightOptions {
33
html?: boolean;
4-
htmlEscaper?: (str: string) => string
4+
htmlEscaper?: (str: string) => string;
55
classPrefix?: string;
66
colors?: {
77
keyword: string;
@@ -20,8 +20,11 @@ declare module 'sql-highlight' {
2020
name: string;
2121
content: string;
2222
}
23-
23+
2424
export function getSegments(sqlString: string): Array<Segment>;
25-
export function highlight(sqlString: string, options?: HighlightOptions): string;
25+
export function highlight(
26+
sqlString: string,
27+
options?: HighlightOptions
28+
): string;
2629
export const DEFAULT_OPTIONS: HighlightOptions;
2730
}

lib/index.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
'use strict'
2-
3-
const keywords = require('./keywords')
4-
const escapeHtml = require('./escapeHtml')
1+
const keywords = require('./keywords');
2+
const escapeHtml = require('./escapeHtml');
53

64
const DEFAULT_OPTIONS = {
75
html: false,
@@ -18,7 +16,7 @@ const DEFAULT_OPTIONS = {
1816
comment: '\x1b[2m\x1b[90m',
1917
clear: '\x1b[0m'
2018
}
21-
}
19+
};
2220

2321
const highlighters = [
2422
/(?<number>[+-]?(?:\d+\.\d+|\d+|\.\d+)(?:E[+-]?\d+)?)/,
@@ -42,44 +40,46 @@ const highlighters = [
4240
// https://data-flair.training/blogs/sql-operators/, plus any single character (in particular ,:;.) not matched by
4341
// the above regexps.
4442
/(?<special>\^-=|\|\*=|\+=|-=|\*=|\/=|%=|&=|>=|<=|<>|!=|!<|!>|>>|<<|.)/
45-
]
43+
];
4644

4745
// Regex of the shape /(?<token1>...)|(?<token2>...)|.../g
4846
const tokenizer = new RegExp(
4947
[
50-
'\\b(?<keyword>' + keywords.join('|') + ')\\b',
51-
...highlighters.map(regex => regex.source)
48+
`\\b(?<keyword>${keywords.join('|')})\\b`,
49+
...highlighters.map((regex) => regex.source)
5250
].join('|'),
5351
'gis'
54-
)
52+
);
5553

56-
function getSegments (sqlString) {
57-
const segments = Array.from(sqlString.matchAll(tokenizer), match => ({
58-
name: Object.keys(match.groups).find(key => match.groups[key]),
54+
function getSegments(sqlString) {
55+
const segments = Array.from(sqlString.matchAll(tokenizer), (match) => ({
56+
name: Object.keys(match.groups).find((key) => match.groups[key]),
5957
content: match[0]
60-
}))
61-
return segments
58+
}));
59+
return segments;
6260
}
6361

64-
function highlight (sqlString, options) {
65-
options = Object.assign({}, DEFAULT_OPTIONS, options)
62+
function highlight(sqlString, options) {
63+
const fullOptions = Object.assign({}, DEFAULT_OPTIONS, options);
6664

6765
return getSegments(sqlString)
6866
.map(({ name, content }) => {
69-
if (options.html) {
70-
const escapedContent = options.htmlEscaper(content)
71-
return name === 'whitespace' ? escapedContent : `<span class="${options.classPrefix}${name}">${escapedContent}</span>`
67+
if (fullOptions.html) {
68+
const escapedContent = fullOptions.htmlEscaper(content);
69+
return name === 'whitespace'
70+
? escapedContent
71+
: `<span class="${fullOptions.classPrefix}${name}">${escapedContent}</span>`;
7272
}
73-
if (options.colors[name]) {
74-
return options.colors[name] + content + options.colors.clear
73+
if (fullOptions.colors[name]) {
74+
return fullOptions.colors[name] + content + fullOptions.colors.clear;
7575
}
76-
return content
76+
return content;
7777
})
78-
.join('')
78+
.join('');
7979
}
8080

8181
module.exports = {
8282
getSegments,
8383
highlight,
8484
DEFAULT_OPTIONS
85-
}
85+
};

lib/keywords.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,4 @@ module.exports = [
142142
'END',
143143
'PRINT',
144144
'OVERLAPS'
145-
]
145+
];

0 commit comments

Comments
 (0)