From 1d57b5d79ca00cae94a45d6af727ecc3107fe661 Mon Sep 17 00:00:00 2001 From: Muneerali199 Date: Mon, 16 Mar 2026 15:21:20 +0530 Subject: [PATCH 1/2] chore: add pre-commit configuration for code quality checks - Added .pre-commit-config.yaml with hooks for file hygiene, config validation, and secret detection Fixes #18 --- .pre-commit-config.yaml | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..85f64d2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,52 @@ +# Pre-commit hooks configuration +# Documentation: https://pre-commit.com/ +# +# Installation: +# pip install pre-commit +# pre-commit install +# +# Usage: +# pre-commit run --all-files # Run on all files +# pre-commit run # Run specific hook +# +# For queries and documentation, visit: https://pre-commit.com/hooks.html + +repos: + # ---------------------------------- + # 1. Universal Git / file hygiene + # ---------------------------------- + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-merge-conflict + - id: check-added-large-files + - id: mixed-line-ending + args: ['--fix=lf'] + + # ---------------------------------- + # 2. Config & data files validation + # ---------------------------------- + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-yaml + - id: check-json + - id: check-toml + + # ---------------------------------- + # 3. Security (language-agnostic) + # ---------------------------------- + - repo: https://github.com/Yelp/detect-secrets + rev: v1.4.0 + hooks: + - id: detect-secrets + + # args: ['--baseline', '.secrets.baseline'] (Maintainers should add a .secrets.baseline file for secret scanning.) + +# ============================================================================== +# IMPORTANT: +# Pre-commit runs locally every time you commit; only simple logic should be included here. +# Heavy operations should be handled by CI/CD pipelines (GitHub Actions, etc.) +# ============================================================================== From 362ee22b91f65ea29e173f14ebd5f5996bcddbc0 Mon Sep 17 00:00:00 2001 From: Muneerali199 Date: Wed, 18 Mar 2026 13:50:56 +0530 Subject: [PATCH 2/2] chore: fix pre-commit hooks configuration per CodeRabbit feedback --- .pre-commit-config.yaml | 15 +- src/social-share-button.js | 311 +++++++++++++++++-------------------- 2 files changed, 146 insertions(+), 180 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 85f64d2..e33f698 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: # 1. Universal Git / file hygiene # ---------------------------------- - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -24,13 +24,6 @@ repos: - id: check-added-large-files - id: mixed-line-ending args: ['--fix=lf'] - - # ---------------------------------- - # 2. Config & data files validation - # ---------------------------------- - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 - hooks: - id: check-yaml - id: check-json - id: check-toml @@ -39,11 +32,11 @@ repos: # 3. Security (language-agnostic) # ---------------------------------- - repo: https://github.com/Yelp/detect-secrets - rev: v1.4.0 + rev: v1.5.0 hooks: - id: detect-secrets - - # args: ['--baseline', '.secrets.baseline'] (Maintainers should add a .secrets.baseline file for secret scanning.) + # Note: Maintainers should run `detect-secrets scan > .secrets.baseline` and uncomment the args below: + # args: ['--baseline', '.secrets.baseline'] # ============================================================================== # IMPORTANT: diff --git a/src/social-share-button.js b/src/social-share-button.js index 5f05397..9353260 100644 --- a/src/social-share-button.js +++ b/src/social-share-button.js @@ -5,39 +5,35 @@ */ /** Analytics event schema version. Increment when the payload shape changes. */ -const ANALYTICS_SCHEMA_VERSION = "1.0"; +const ANALYTICS_SCHEMA_VERSION = '1.0'; class SocialShareButton { constructor(options = {}) { this.options = { - url: - options.url || - (typeof window !== "undefined" ? window.location.href : ""), - title: - options.title || - (typeof document !== "undefined" ? document.title : ""), - description: options.description || "", + url: options.url || (typeof window !== 'undefined' ? window.location.href : ''), + title: options.title || (typeof document !== 'undefined' ? document.title : ''), + description: options.description || '', hashtags: options.hashtags || [], - via: options.via || "", + via: options.via || '', platforms: options.platforms || [ - "whatsapp", - "facebook", - "twitter", - "linkedin", - "telegram", - "reddit", + 'whatsapp', + 'facebook', + 'twitter', + 'linkedin', + 'telegram', + 'reddit', ], - theme: options.theme || "dark", - buttonText: options.buttonText || "Share", - customClass: options.customClass || "", - buttonColor: options.buttonColor || "", - buttonHoverColor: options.buttonHoverColor || "", + theme: options.theme || 'dark', + buttonText: options.buttonText || 'Share', + customClass: options.customClass || '', + buttonColor: options.buttonColor || '', + buttonHoverColor: options.buttonHoverColor || '', onShare: options.onShare || null, onCopy: options.onCopy || null, container: options.container || null, showButton: options.showButton !== false, - buttonStyle: options.buttonStyle || "default", - modalPosition: options.modalPosition || "center", + buttonStyle: options.buttonStyle || 'default', + modalPosition: options.modalPosition || 'center', // Analytics — the library emits events but never collects or sends data itself. // Website owners wire up their own analytics tools via these options. analytics: options.analytics !== false, // set to false to disable all event emission @@ -55,14 +51,13 @@ class SocialShareButton { this.handleKeydown = null; this.listeners = []; // Central registry for all event listeners - this.openTimeout = null; // Track setTimeout for openModal animation + this.openTimeout = null; // Track setTimeout for openModal animation this.closeTimeout = null; // Track setTimeout for closeModal animation this.feedbackTimeout = null; // Track setTimeout for copy feedback reset this.ownsBodyLock = false; // Track if this instance owns the body overflow lock this.eventsAttached = false; // Guard against multiple attachEvents() calls this.isDestroyed = false; // Track if instance has been destroyed (prevents async callbacks) - if (this.options.container) { this.init(); } @@ -78,9 +73,9 @@ class SocialShareButton { } createButton() { - const button = document.createElement("button"); + const button = document.createElement('button'); button.className = `social-share-btn ${this.options.buttonStyle} ${this.options.customClass}`; - button.setAttribute("aria-label", "Share"); + button.setAttribute('aria-label', 'Share'); button.innerHTML = `