From eace1d877b8e222e67f91ef02e50f062654db4e8 Mon Sep 17 00:00:00 2001 From: rocktimsaikia Date: Wed, 27 May 2026 17:03:32 +0530 Subject: [PATCH] build: replace ESLint with Biome for linting and formatting --- .eslintrc | 18 ---------- biome.json | 27 ++++++++++++++ package.json | 7 ++-- rollup.config.js | 16 ++++----- src/escape.js | 12 +++---- src/format.js | 23 ++++++------ src/index.js | 93 ++++++++++++++++++++++++------------------------ 7 files changed, 101 insertions(+), 95 deletions(-) delete mode 100644 .eslintrc create mode 100644 biome.json diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index a9414a2..0000000 --- a/.eslintrc +++ /dev/null @@ -1,18 +0,0 @@ -{ - "env": { - "browser": true - }, - "extends": "airbnb-base", - "parserOptions": { - "ecmaVersion": 2021, - "sourceType": "module" - }, - "rules": { - "class-methods-use-this":"off", - "import/extensions": "off", - "no-underscore-dangle":"off" - }, - "ignorePatterns": [ - "dist" - ] -} diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..28a8c5a --- /dev/null +++ b/biome.json @@ -0,0 +1,27 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.4.15/schema.json", + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true + }, + "files": { + "ignoreUnknown": true, + "includes": ["**", "!.claude"] + }, + "formatter": { + "enabled": true, + "indentStyle": "tab" + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + "javascript": { + "formatter": { + "quoteStyle": "single" + } + } +} diff --git a/package.json b/package.json index d6a3c4b..280f1cb 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "dist" ], "scripts": { - "lint": "eslint .", + "lint": "biome check .", + "format": "biome check --write .", "build": "rollup -c", "build-watch": "npm run build --watch", "prebuild": "del-cli dist && npm run lint", @@ -37,10 +38,8 @@ }, "homepage": "https://github.com/RocktimSaikia/github-card#readme", "devDependencies": { + "@biomejs/biome": "2.4.15", "del-cli": "^3.0.1", - "eslint": "^7.24.0", - "eslint-config-airbnb-base": "14.2.1", - "eslint-plugin-import": "2.22.1", "rollup": "^2.45.2", "rollup-plugin-uglify": "^6.0.4" } diff --git a/rollup.config.js b/rollup.config.js index af6708f..53ded3a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,12 +2,12 @@ import { uglify } from 'rollup-plugin-uglify'; import pkg from './package.json'; export default [ - { - input: 'src/index.js', - output: { - file: pkg.module, - format: 'es', - }, - plugins: [uglify()], - }, + { + input: 'src/index.js', + output: { + file: pkg.module, + format: 'es', + }, + plugins: [uglify()], + }, ]; diff --git a/src/escape.js b/src/escape.js index ab74612..4069539 100644 --- a/src/escape.js +++ b/src/escape.js @@ -1,12 +1,12 @@ // Escape user-controlled values (e.g. GitHub name/bio) before injecting them // into the card's innerHTML, to prevent HTML/attribute injection. function escapeHtml(value) { - return String(value) - .replace(/&/g, '&') - .replace(//g, '>') - .replace(/"/g, '"') - .replace(/'/g, '''); + return String(value) + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); } export default escapeHtml; diff --git a/src/format.js b/src/format.js index 18f07b3..ae16c94 100644 --- a/src/format.js +++ b/src/format.js @@ -1,18 +1,17 @@ -/* eslint-disable no-restricted-properties */ function nFormatter(value) { - if (!(value >= 1000)) return value; - let newValue = value; - const suffixes = ['', 'K', 'M', 'B', 'T']; - let suffixNum = 0; - while (newValue >= 1000) { - newValue /= 1000; - suffixNum += 1; - } + if (!(value >= 1000)) return value; + let newValue = value; + const suffixes = ['', 'K', 'M', 'B', 'T']; + let suffixNum = 0; + while (newValue >= 1000) { + newValue /= 1000; + suffixNum += 1; + } - newValue = newValue.toPrecision(3); + newValue = newValue.toPrecision(3); - newValue += suffixes[suffixNum]; - return newValue; + newValue += suffixes[suffixNum]; + return newValue; } export default nFormatter; diff --git a/src/index.js b/src/index.js index a27b01f..b2dd242 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,6 @@ -/* eslint no-undef: 0 */ -import widgetStyle from './style.js'; -import nFormatter from './format.js'; import escapeHtml from './escape.js'; +import nFormatter from './format.js'; +import widgetStyle from './style.js'; const template = document.createElement('template'); @@ -13,56 +12,56 @@ template.innerHTML = ` `; class myCard extends HTMLElement { - constructor() { - super(); + constructor() { + super(); - this._shadowRoot = this.attachShadow({ mode: 'open' }); - this._shadowRoot.append(template.content.cloneNode(true)); - } + this._shadowRoot = this.attachShadow({ mode: 'open' }); + this._shadowRoot.append(template.content.cloneNode(true)); + } - static get observedAttributes() { - return ['data-theme']; - } + static get observedAttributes() { + return ['data-theme']; + } - attributeChangedCallback(attr, oldValue, newValue) { - if (attr === 'data-theme' && oldValue !== newValue) { - this.setTheme(newValue); - } - } + attributeChangedCallback(attr, oldValue, newValue) { + if (attr === 'data-theme' && oldValue !== newValue) { + this.setTheme(newValue); + } + } - connectedCallback() { - this.fetchData(this.getAttribute('data-user')).then((response) => { - const cardTemplate = this.createCard(response); - this._shadowRoot.querySelector('.card').innerHTML = cardTemplate; - }); - } + connectedCallback() { + this.fetchData(this.getAttribute('data-user')).then((response) => { + const cardTemplate = this.createCard(response); + this._shadowRoot.querySelector('.card').innerHTML = cardTemplate; + }); + } - setTheme(theme) { - switch (theme) { - case 'dark': - this._shadowRoot.querySelector('.card').classList.add('dark'); - break; - default: - this._shadowRoot.querySelector('.card').classList.remove('dark'); - break; - } - } + setTheme(theme) { + switch (theme) { + case 'dark': + this._shadowRoot.querySelector('.card').classList.add('dark'); + break; + default: + this._shadowRoot.querySelector('.card').classList.remove('dark'); + break; + } + } - /** Fetch the data */ - async fetchData(response) { - const data = await fetch(`https://api.github.com/users/${response}`, { - method: 'GET', - }); - const responseult = await data.json(); - return responseult; - } + /** Fetch the data */ + async fetchData(response) { + const data = await fetch(`https://api.github.com/users/${response}`, { + method: 'GET', + }); + const responseult = await data.json(); + return responseult; + } - createCard(user) { - const login = escapeHtml(user.login); - const htmlUrl = escapeHtml(user.html_url); - const name = escapeHtml(user.name); - const bio = escapeHtml(user.bio ?? ''); - return ` + createCard(user) { + const login = escapeHtml(user.login); + const htmlUrl = escapeHtml(user.html_url); + const name = escapeHtml(user.name); + const bio = escapeHtml(user.bio ?? ''); + return `
@@ -90,7 +89,7 @@ class myCard extends HTMLElement {
`; - } + } } customElements.define('github-card', myCard);