Node.js environment में Clang का उपयोग करने वाला C, C++, Java, JavaScript, JSON, Objective-C, C# formatter
(clang-format-node.lumir.page)मैंने Node.js environment में Clang का उपयोग करने वाला C, C++, Java, JavaScript, JSON, Objective-C, C# formatter विकसित किया है। यह प्रोजेक्ट angular के उस clang-format package पर आधारित एक नया प्रोजेक्ट है, जिसका अब maintenance नहीं होता और जो deprecated हो चुका है.
इस समय बहुत से लोगों ने इसमें रुचि दिखाई है, और कई legacy users के migrate करने की वजह से monthly downloads 20,000 को पार कर चुके हैं।
इसके अलावा, इस package ने full test coverage हासिल कर ली है, और Node.js core में मौजूदा angular clang-format project की जगह इस package को इस्तेमाल करने के लिए एक PR भी खुला हुआ है, इसलिए इसकी stability पर भरोसा करके इस्तेमाल किया जा सकता है।
यह package LLVM के C compiler के लिए मशहूर Clang के clang-format पर आधारित है, और C, C++, Java जैसी कई भाषाओं के code formatting को संभालता है। Node.js environment में यह Prettier की तरह ही भूमिका निभाता है, जो सबसे लोकप्रिय packages में से एक है।
हालाँकि, Prettier package C, C++, Java जैसी native languages की formatting को support नहीं करता, इसलिए इन भाषाओं में formatting के लिए अक्सर clang-format का उपयोग किया जाता है।
Node.js environment में clang-format खास तौर पर तब उपयोगी है जब, Node.js core development की तरह, JavaScript code और C, C++ जैसी native code को साथ में लिखना हो। मौजूदा clang-format के मामले में, package का latest version इस्तेमाल करने के लिए अतिरिक्त dependencies install करनी पड़ती थीं, लेकिन इस package के साथ इसकी ज़रूरत नहीं है।
इसके अलावा, मौजूदा clang-format package को CI आदि में Node.js और npm वाले workflow में integrate करना काफ़ी कठिन था, लेकिन इस package के साथ बस npm से download करके script setting कर देना काफ़ी है, इसलिए CI environment में इसके कई फ़ायदे हैं।
मुख्य बिंदु इस प्रकार हैं:
- समर्थित भाषाएँ: C, C++, Java, JavaScript, JSON, Objective‑C, C# — clang-format आधारित formatter
- Fully Secure Binaries: LLVM के official source से सीधे build. GitHub Actions Attestation Provenances और npm Build Provenances के साथ पूरी तरह verified
- Zero dependencies: Python, C++ toolchain, npm sub-dependencies की ज़रूरत नहीं — सिर्फ़ pure Node.js पर चलता है
- Drop-in replacement: deprecated angular/clang-format को replace करने के लिए design किया गया
- व्यापक platform support: OS/architecture, Node.js versions, GitHub Actions runner images, Docker build images आदि का विस्तृत समर्थन
- CI-friendly: npm install + simple script से CI integration संभव — complex native setup की ज़रूरत नहीं
- स्वचालित build·release: clang-format के हर update पर GitHub Actions build·verification·PR creation करता है → npm पर नया version अपने आप publish
- stability indicators: full test coverage, monthly downloads 20,000+, Node.js core में पुराने angular package को replace करने वाला PR प्रगति पर
- नई सुविधा (1.2.0): git-clang-format wrapper — बदली गई files की सिर्फ़ ‘changed lines’ को format करता है, ताकि बड़े repositories में commit history खराब होने को कम किया जा सके
git-clang-format क्यों महत्वपूर्ण है?
- बड़े projects में पूरे repository को reformat करने से commit history गड़बड़ा सकती है।
- git-clang-format केवल उन lines को format करता है जिन्हें वास्तव में बदला गया है, जिससे gradual adoption संभव होता है और समय के साथ style consistency स्वाभाविक रूप से बनती जाती है।
- lint-staged की तरह file-level नहीं, बल्कि line-level पर अधिक बारीकी से apply किया जा सकता है।
किस तरह की स्थितियों के लिए उपयुक्त है?
- ऐसे repositories जहाँ Node.js और C/C++/Java जैसी native code साथ में मौजूद हों
- जब CI pipeline में native toolchain install किए बिना formatting को सरल तरीके से apply करना हो
- angular/clang-format इस्तेमाल कर रहे legacy users के लिए सुरक्षित migration
लिंक
- official documentation: https://clang-format-node.lumir.page
- repository: https://github.com/lumirlumir/npm-clang-format-node
अभी कोई टिप्पणी नहीं है.