Added vscodium

This commit is contained in:
Kristofers Solo
2022-04-28 21:17:01 +03:00
parent 837a479d82
commit d7dddc39ef
29139 changed files with 250215 additions and 45125 deletions

View File

@@ -0,0 +1,3 @@
# These are supported funding model platforms
github: aaron-bond

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Language="en-US" Id="better-comments" Version="3.0.0" Publisher="aaron-bond" />
<DisplayName>Better Comments</DisplayName>
<Description xml:space="preserve">Improve your code commenting by annotating with alert, informational, TODOs, and more!</Description>
<Tags></Tags>
<Categories>Formatters</Categories>
<GalleryFlags>Public</GalleryFlags>
<Properties>
<Property Id="Microsoft.VisualStudio.Code.Engine" Value="^1.65.0" />
<Property Id="Microsoft.VisualStudio.Code.ExtensionDependencies" Value="" />
<Property Id="Microsoft.VisualStudio.Code.ExtensionPack" Value="" />
<Property Id="Microsoft.VisualStudio.Code.ExtensionKind" Value="ui,workspace" />
<Property Id="Microsoft.VisualStudio.Code.LocalizedLanguages" Value="" />
<Property Id="Microsoft.VisualStudio.Services.Links.Source" Value="https://github.com/aaron-bond/better-comments.git" />
<Property Id="Microsoft.VisualStudio.Services.Links.Getstarted" Value="https://github.com/aaron-bond/better-comments.git" />
<Property Id="Microsoft.VisualStudio.Services.Links.GitHub" Value="https://github.com/aaron-bond/better-comments.git" />
<Property Id="Microsoft.VisualStudio.Services.Links.Support" Value="https://github.com/aaron-bond/better-comments/issues" />
<Property Id="Microsoft.VisualStudio.Services.Links.Learn" Value="https://github.com/aaron-bond/better-comments/blob/master/README.md" />
<Property Id="Microsoft.VisualStudio.Services.Branding.Color" Value="#e3f4ff" />
<Property Id="Microsoft.VisualStudio.Services.Branding.Theme" Value="light" />
<Property Id="Microsoft.VisualStudio.Services.GitHubFlavoredMarkdown" Value="true" />
</Properties>
<License>extension/LICENSE.md</License>
<Icon>extension/icon.png</Icon>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Code"/>
</Installation>
<Dependencies/>
<Assets>
<Asset Type="Microsoft.VisualStudio.Code.Manifest" Path="extension/package.json" Addressable="true" />
<Asset Type="Microsoft.VisualStudio.Services.Content.Details" Path="extension/README.md" Addressable="true" />
<Asset Type="Microsoft.VisualStudio.Services.Content.Changelog" Path="extension/CHANGELOG.md" Addressable="true" />
<Asset Type="Microsoft.VisualStudio.Services.Content.License" Path="extension/LICENSE.md" Addressable="true" />
<Asset Type="Microsoft.VisualStudio.Services.Icons.Default" Path="extension/icon.png" Addressable="true" />
</Assets>
</PackageManifest>

View File

@@ -0,0 +1,229 @@
# Change Log
## [3.0.0] (2022-??-??)
### Features
* Adding built in support for all languages ([e1373bf](https://github.com/aaron-bond/better-comments/commit/e1373bf)). Massive thanks to _edgardmessias_
### House Keeping
* Version bumped all dependencies
* Language support is now driven from configuration files. This means that if you have an extension which informs VSCode about a language, Better Comments will know about it too!
* Problems are likely to arise with this change, but it allows a lot more users to benefit from Better Comments without needing an explicit update for the extension adding support.
__With version 3.0.0 comes the addition of the support button on the Github page for [Better Comments](https://github.com/sponsors/aaron-bond)__
__If you feel my work on this extension has earned me a coffee, that's the place to do it!__
_**Thanks!**_
## [2.1.0] (2020-07-13)
### Features
* Adding Bold, Italic, and Underline ([e41ccc4](https://github.com/aaron-bond/better-comments/commit/e41ccc4)), closes [#50](https://github.com/aaron-bond/better-comments/issues/50). Massive thanks to _Fr33maan_
* Adding XML support
* Adding BrightScript support
### Bug Fixes
* Fixing Shaderlab support ([f96049f](https://github.com/aaron-bond/better-comments/commit/f96049f)), closes [#245](https://github.com/aaron-bond/better-comments/issues/245)
* Fixing SASS support ([7decffb](https://github.com/aaron-bond/better-comments/commit/7decffb)), closes [#123](https://github.com/aaron-bond/better-comments/issues/123), [#215](ttps://github.com/aaron-bond/better-comments/issues/215)
## [2.0.5] (2019-05-15)
### Features
* Adding Markdown support ([54e51fb](https://github.com/aaron-bond/better-comments/commit/54e51fb)), closes [#91](https://github.com/aaron-bond/better-comments/issues/91)
* Adding Apex support ([301644e](https://github.com/aaron-bond/better-comments/commit/301644e)), closes [#143](https://github.com/aaron-bond/better-comments/issues/143)
* Adding GenStat support ([a14e24c](https://github.com/aaron-bond/better-comments/commit/a14e24c)), closes [#149](https://github.com/aaron-bond/better-comments/issues/149)
* Adding ColdFusion support ([9e2a4be](https://github.com/aaron-bond/better-comments/commit/9e2a4be)), closes [#135](https://github.com/aaron-bond/better-comments/issues/135)
## [2.0.4] (2019-05-14)
### Bug Fixes
* Fixing Groovy support ([099bcc0](https://github.com/aaron-bond/better-comments/commit/099bcc0)), closes [#150](https://github.com/aaron-bond/better-comments/issues/150)
* Fixing multiline Lua support ([7ca3164](https://github.com/aaron-bond/better-comments/commit/7ca3164)), closes [#151](https://github.com/aaron-bond/better-comments/issues/151)
### Features
* Supporting remote development, closes [#147](https://github.com/aaron-bond/better-comments/issues/147). Thanks _mjbvz_
* Adding Elm support, merges [#146](https://github.com/aaron-bond/better-comments/pull/146). Thanks _ChristianPredebon_
## [2.0.3] (2018-11-04)
### Features
* Adding Stylus support ([a57ad30](https://github.com/aaron-bond/better-comments/commit/a57ad30)), merges [#112](https://github.com/aaron-bond/better-comments/issues/112). Thanks _vednoc_
* Adding ASCIIDoc support ([60a5f5f](https://github.com/aaron-bond/better-comments/commit/60a5f5f)), closes [#107](https://github.com/aaron-bond/better-comments/issues/107)
## [2.0.2] (2018-10-10)
### Bug Fixes
* Fixing single line CSS comments([469a93f](https://github.com/aaron-bond/better-comments/commit/469a93f)), closes [#109](https://github.com/aaron-bond/better-comments/issues/109)
* Fixing support for multiline Haskell comments ([498016a](https://github.com/aaron-bond/better-comments/commit/498016a)), closes [#102](https://github.com/aaron-bond/better-comments/issues/102)
### Features
* Adding D support ([c6a619c](https://github.com/aaron-bond/better-comments/commit/c6a619c)), closes [#99](https://github.com/aaron-bond/better-comments/issues/99)
## [2.0.1] (2018-09-26)
### Bug Fixes
* Fixing issue where JSDoc block comments weren't being detected properly ([7cb9126](https://github.com/aaron-bond/better-comments/commit/7cb9126)), closes [#101](https://github.com/aaron-bond/better-comments/issues/101)
## [2.0.0] (2018-09-20)
### Features
* Block comments for lots and lots of languages. Please raise a bug or feature request if I've missed any!
* Added support for HTML
* Added support for Twig
* Added support for Puppet
### House Keeping
* I decided a major version release was appropriate for this one as it's a pretty huge set of changes in terms of how the extension functions
* It's now possible to add block comment formatting for any new languages as required. Sorry it took so long!
## [1.3.0] (2018-09-13)
### Features
* Adding support for Bibtex/Biblatex ([d1f06b6](https://github.com/aaron-bond/better-comments/commit/d1f06b6)), thanks to _JavierReyes945_, merges [#96](https://github.com/aaron-bond/better-comments/pull/96)
* Adding support for Verilog HDL ([b368b17](https://github.com/aaron-bond/better-comments/commit/b368b17)), closes [#84](https://github.com/aaron-bond/better-comments/issues/84)
### Bug Fixes
* Fixing multiline comment support for SAS and Stata ([4b40bd9](https://github.com/aaron-bond/better-comments/commit/4b40bd9)), closes [#95](https://github.com/aaron-bond/better-comments/issues/95)
## [1.2.9] (2018-09-08)
### Features
* Adding support for PlantUML ([9a446a3](https://github.com/aaron-bond/better-comments/commit/9a446a3)), thanks to _JavierReyes945_, closes [#94](https://github.com/aaron-bond/better-comments/issues/94)
## [1.2.8] (2018-09-03)
### Features
* Added support for Tcl ([52e6d35](https://github.com/aaron-bond/better-comments/commit/52e6d35)), closes [#92](https://github.com/aaron-bond/better-comments/issues/92)
## [1.2.7] (2018-09-02)
### Features
* Adding support for Flax ([71f6326](https://github.com/aaron-bond/better-comments/commit/71f6326)), merges [#76](https://github.com/aaron-bond/better-comments/issues/76)
* Adding support for multiple languages, closes [#89](https://github.com/aaron-bond/better-comments/issues/89)
* Fortran (modern) ([8762226](https://github.com/aaron-bond/better-comments/commit/8762226))
* SAS ([145e8d3](https://github.com/aaron-bond/better-comments/commit/145e8d3))
* STATA ([eb0f367](https://github.com/aaron-bond/better-comments/commit/eb0f367))
### House Keeping
* Updating README to reflect actual styntax better ([71f9019](https://github.com/aaron-bond/better-comments/commit/71f9019)), merges [#77](https://github.com/aaron-bond/better-comments/issues/77)
* Messed up the incrementing of the version on this one with the gdscript merge so just pushing this as 1.2.7 for convenience
## [1.2.5] (2018-06-04)
### Features
* Adding support for COBOL ([7939ca2](https://github.com/aaron-bond/better-comments/commit/7939ca2)), merges [#34](https://github.com/aaron-bond/better-comments/issues/34)
### Bug Fixes
* Fixing plaintext highlight even when setting is false ([7939ca2](https://github.com/aaron-bond/better-comments/commit/7939ca2)), closes [#73](https://github.com/aaron-bond/better-comments/issues/73)
## [1.2.4] (2018-05-31)
### Features
* Adding new property for tags: **backgroundColor** ([3e7a188](https://github.com/aaron-bond/better-comments/commit/3e7a188)), closes [#66](https://github.com/aaron-bond/better-comments/issues/66)
- default: `transparent`
* Adding support for: PlainText ([27ff774](https://github.com/aaron-bond/better-comments/commit/27ff774)), closes [#39](https://github.com/aaron-bond/better-comments/issues/39)
- PlainText support must be turned on in the settings: `highlightPlainText`
* Adding support for: Vue.js ([2b14d2e](https://github.com/aaron-bond/better-comments/commit/2b14d2e)), closes [#71](https://github.com/aaron-bond/better-comments/issues/71)
* Adding support for: nim ([73a55f6](https://github.com/aaron-bond/better-comments/commit/73a55f6)), merges [#68](https://github.com/aaron-bond/better-comments/issues/68)
* Adding support for: HiveQL and Pig ([e1653ef](https://github.com/aaron-bond/better-comments/commit/e1653ef)), merges [#63](https://github.com/aaron-bond/better-comments/issues/63)
## [1.2.3] (2018-05-20)
### Features
* Adding support for: Dart ([7490b81](https://github.com/aaron-bond/better-comments/commit/7490b81)), closes [#65](https://github.com/aaron-bond/better-comments/issues/65)
* Adding support for: Matlab ([e35541b](https://github.com/aaron-bond/better-comments/commit/e35541b)), closes [#58](https://github.com/aaron-bond/better-comments/issues/58)
### Bug Fixes
* Fixing support for SCSS ([2b3919f](https://github.com/aaron-bond/better-comments/commit/2b3919f)), closes [#60](https://github.com/aaron-bond/better-comments/issues/60)
* Fixing Python to prevent first line of the file being detected as a comment,
([438e0a6](https://github.com/aaron-bond/better-comments/commit/438e0a6)), closes [#61](https://github.com/aaron-bond/better-comments/issues/61)
## [1.2.2] (2018-04-15)
### Features
* Adding support for: JSON with comments ([6f0b330](https://github.com/aaron-bond/better-comments/commit/6f0b330)), closes [#51](https://github.com/aaron-bond/better-comments/issues/51)
* Adding support for: AL ([de86410](https://github.com/aaron-bond/better-comments/commit/de86410)), closes [#54](https://github.com/aaron-bond/better-comments/issues/54)
* Adding support for: TypeScript React (.tsx) ([e884b37](https://github.com/aaron-bond/better-comments/commit/e884b37)), closes [#56](https://github.com/aaron-bond/better-comments/issues/56)
## [1.2.1] (2018-03-20)
### Features
* Adding support for: Terraform ([c5edd8d](https://github.com/aaron-bond/better-comments/commit/c5edd8d)), closes [#48](https://github.com/aaron-bond/better-comments/issues/48)
### Bug Fixes
* Fixing logic to run the decorations properly when switching back from an unsupported language ([756e0e0](https://github.com/aaron-bond/better-comments/commit/756e0e0)), closes [#47](https://github.com/aaron-bond/better-comments/issues/47)
* Fixing decoration of strikethrough on multiline comments to start in the correct location ([c4372e7](https://github.com/aaron-bond/better-comments/commit/c4372e7)), closes [#46](https://github.com/aaron-bond/better-comments/issues/46)
## [1.2.0] (2018-03-19)
### Features
* Adding support for: Clojure, Racket, Lisp ([88e0720](https://github.com/aaron-bond/better-comments/commit/88e0720)), merges [#40](https://github.com/aaron-bond/better-comments/pull/40)
* Adding support for: Yaml ([e9f40a0](https://github.com/aaron-bond/better-comments/commit/e9f40a0)), merges [#37](https://github.com/aaron-bond/better-comments/pull/37)
* Adding support for: Pascal ([655f61f](https://github.com/aaron-bond/better-comments/commit/655f61f)), closes [#41](https://github.com/aaron-bond/better-comments/pull/37)
### Bug Fixes
* Fixing crash when unsupported language is opened in the window ([e9f40a0](https://github.com/aaron-bond/better-comments/commit/e9f40a0)), closes [#35](https://github.com/aaron-bond/better-comments/issues/35)
## [1.1.9] (2018-02-11)
### Features
* Adding support for Julia ([1b24ce1](https://github.com/aaron-bond/better-comments/commit/1b24ce1))
## [1.1.8] (2018-01-23)
### Features
* Adding support for GraphQL ([bcfcefa](https://github.com/aaron-bond/better-comments/commit/bcfcefa)), closes [#28](https://github.com/aaron-bond/better-comments/issues/28)
### Bug Fixes
* Expanding non-JSDoc block comment detection ([dccd467](https://github.com/aaron-bond/better-comments/commit/dccd467)), closes [#20](https://github.com/aaron-bond/better-comments/issues/20)
## [1.1.7] (2018-01-07)
### Bug Fixes
* Fixing comment detection when tabs are used to start the comment ([2f08fb9](https://github.com/aaron-bond/better-comments/commit/2f08fb9)), closes [#25](https://github.com/aaron-bond/better-comments/issues/25), thanks to _bekorn_
## [1.1.6] (2018-01-15)
### Features
* Adding multiple new languages ([586f325](https://github.com/aaron-bond/better-comments/commit/586f325)), thanks to _Jooseppi12_
## [1.1.5] (2018-01-14)
#### Bug Fixes
* Fixing multiline comment detection with non-English characters ([deff42b](https://github.com/aaron-bond/better-comments/commit/deff42b)), closes [#24](https://github.com/aaron-bond/better-comments/issues/24)
## [1.1.4] (2018-01-04)
#### Features
* Adding activation event and new comment type for VB.NET ("vb") ([45199a9](https://github.com/aaron-bond/better-comments/commit/45199a9)), closes [#21](https://github.com/aaron-bond/better-comments/issues/21)
## [1.1.3] (2017-12-22)
#### Features
* Adding activation event for React ("javascriptreact") ([e54ae83](https://github.com/aaron-bond/better-comments/commit/e54ae83)), closes [#19](https://github.com/aaron-bond/better-comments/issues/19)
## [1.1.2] (2017-12-16)
#### Bug Fixes
* Fixed wrong delimiter for Lua ([4bb1e2f](https://github.com/aaron-bond/better-comments/commit/4bb1e2f)), closes [#17](https://github.com/aaron-bond/better-comments/issues/17)
## [1.1.1] (2017-12-12) : Accidental Increment
#### Bug Fixes
* Fixing issue with options configuration ([0a00618](https://github.com/aaron-bond/better-comments/commit/0a00618)), closes [#16](https://github.com/aaron-bond/better-comments/issues/16)
## [1.0.0] (2017-12-06)
#### Bug Fixes
* Fixing support for JSDoc style block comments ([69a36bf](https://github.com/aaron-bond/better-comments/commit/69a36bf)), closes [#13](https://github.com/aaron-bond/better-comments/issues/13)
#### Features
* Adding support for MANY languages ([0e7eab9](https://github.com/aaron-bond/better-comments/commit/0e7eab9d352780bfb303caf090e186c15bdcc77b)), closes [#8](https://github.com/aaron-bond/better-comments/issues/8), [#9](https://github.com/aaron-bond/better-comments/issues/9)
* Adding customisable comment annotation indicators, closes [#11](https://github.com/aaron-bond/better-comments/issues/11)
## [0.1.3] (2017-07-17)
#### Bug Fixes
* Fixing an issue where multi-line comments would not be detected if preceded by some indentation ([c36821b](https://github.com/aaron-bond/better-comments/commit/c36821b))
#### Features
* Adding language support for `Go`
Thanks to **pwebly** for both of these additions :)
## [0.1.2] (2017-07-14)
#### Bug Fixes
* Fixing issue with `TODO` and `:` in multiline comments ([5f4d049](https://github.com/aaron-bond/better-comments/commit/5f4d049)), closes [#5](https://github.com/aaron-bond/better-comments/issues/5)
## [0.1.1] (2017-07-12)
#### Features
* Adding language support for `C` (thanks to _TheWhoAreYouPerson_) ([6f3b852](https://github.com/aaron-bond/better-comments/commit/6f3b852))
* Adding support for multiline comments (special thanks to _kurozael_ for the suggestion and help implementing) ([cc82fca](https://github.com/aaron-bond/better-comments/commit/cc82fca))
- Also adding contribution point for this: **multilineComments**: set this to false to disable
## [0.1.0] (2017-06-15)
#### Features
* Adding new comment type contribution point: **highlightColor** ([07bd22f](https://github.com/aaron-bond/better-comments/commit/07bd22f))
#### Bug Fixes
* Fixing issue where comment format conflicts with linters expecting a space after initial `//` (special thanks to _TobiasBales_)
#### House Keeping
* Added TravisCI config to run unit tests on check in ([bd4b7b2](https://github.com/aaron-bond/better-comments/commit/bd4b7b2))
* Updated README and demo image to show new comment type ([0cbbccb](https://github.com/aaron-bond/better-comments/commit/0cbbccb))
## [0.0.3] (2017-06-09)
Initial release to VSCode marketplace

View File

@@ -0,0 +1,8 @@
MIT License
Copyright (c) 2017 Aaron Bond
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,161 @@
# Better Comments
The Better Comments extension will help you create more human-friendly comments in your code.
With this extension, you will be able to categorise your annotations into:
* Alerts
* Queries
* TODOs
* Highlights
* Commented out code can also be styled to make it clear the code shouldn't be there
* Any other comment styles you'd like can be specified in the settings
![Annotated code](https://github.com/aaron-bond/better-comments/raw/HEAD/images/better-comments.PNG)
## Configuration
This extension can be configured in User Settings or Workspace settings.
`"better-comments.multilineComments": true`
This setting will control whether multiline comments are styled using the annotation tags.
When false, multiline comments will be presented without decoration.
`"better-comments.highlightPlainText": false`
This setting will control whether comments in a plain text file are styled using the annotation tags.
When true, the tags (defaults: `! * ? //`) will be detected if they're the first character on a line.
`better-comments.tags`
The tags are the characters or sequences used to mark a comment for decoration.
The default 5 can be modified to change the colors, and more can be added.
```json
"better-comments.tags": [
{
"tag": "!",
"color": "#FF2D00",
"strikethrough": false,
"underline": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "?",
"color": "#3498DB",
"strikethrough": false,
"underline": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "//",
"color": "#474747",
"strikethrough": true,
"underline": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "todo",
"color": "#FF8C00",
"strikethrough": false,
"underline": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "*",
"color": "#98C379",
"strikethrough": false,
"underline": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
}
]
```
## Supported Languages
* Ada
* AL
* Apex
* AsciiDoc
* BrightScript
* C
* C#
* C++
* ColdFusion
* Clojure
* COBOL
* CoffeeScript
* CSS
* Dart
* Dockerfile
* Elixir
* Elm
* Erlang
* F#
* Fortran
* gdscript
* GenStat
* Go
* GraphQL
* Groovy
* Haskell
* Haxe
* HiveQL
* HTML
* Java
* JavaScript
* JavaScript React
* JSON with comments
* Julia
* Kotlin
* LaTex (inlc. Bibtex/Biblatex)
* Less
* Lisp
* Lua
* Makefile
* Markdown
* Nim
* MATLAB
* Objective-C
* Objective-C++
* Pascal
* Perl
* Perl 6
* PHP
* Pig
* PlantUML
* PL/SQL
* PowerShell
* Puppet
* Python
* R
* Racket
* Ruby
* Rust
* SAS
* Sass
* Scala
* SCSS
* ShaderLab
* ShellScript
* SQL
* STATA
* Stylus
* Svelte
* Swift
* Tcl
* Terraform
* Twig
* TypeScript
* TypeScript React
* Verilog
* Visual Basic
* Vue.js
* XML
* YAML

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

@@ -0,0 +1,23 @@
MIT License
Copyright (c) 2012-2018 Aseem Kishore, and [others].
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
[others]: https://github.com/json5/json5/contributors

View File

@@ -0,0 +1,234 @@
# JSON5 JSON for Humans
[![Build Status](https://travis-ci.com/json5/json5.svg)][Build Status]
[![Coverage
Status](https://coveralls.io/repos/github/json5/json5/badge.svg)][Coverage
Status]
The JSON5 Data Interchange Format (JSON5) is a superset of [JSON] that aims to
alleviate some of the limitations of JSON by expanding its syntax to include
some productions from [ECMAScript 5.1].
This JavaScript library is the official reference implementation for JSON5
parsing and serialization libraries.
[Build Status]: https://travis-ci.com/json5/json5
[Coverage Status]: https://coveralls.io/github/json5/json5
[JSON]: https://tools.ietf.org/html/rfc7159
[ECMAScript 5.1]: https://www.ecma-international.org/ecma-262/5.1/
## Summary of Features
The following ECMAScript 5.1 features, which are not supported in JSON, have
been extended to JSON5.
### Objects
- Object keys may be an ECMAScript 5.1 _[IdentifierName]_.
- Objects may have a single trailing comma.
### Arrays
- Arrays may have a single trailing comma.
### Strings
- Strings may be single quoted.
- Strings may span multiple lines by escaping new line characters.
- Strings may include character escapes.
### Numbers
- Numbers may be hexadecimal.
- Numbers may have a leading or trailing decimal point.
- Numbers may be [IEEE 754] positive infinity, negative infinity, and NaN.
- Numbers may begin with an explicit plus sign.
### Comments
- Single and multi-line comments are allowed.
### White Space
- Additional white space characters are allowed.
[IdentifierName]: https://www.ecma-international.org/ecma-262/5.1/#sec-7.6
[IEEE 754]: http://ieeexplore.ieee.org/servlet/opac?punumber=4610933
## Short Example
```js
{
// comments
unquoted: 'and you can quote me on that',
singleQuotes: 'I can use "double quotes" here',
lineBreaks: "Look, Mom! \
No \\n's!",
hexadecimal: 0xdecaf,
leadingDecimalPoint: .8675309, andTrailing: 8675309.,
positiveSign: +1,
trailingComma: 'in objects', andIn: ['arrays',],
"backwardsCompatible": "with JSON",
}
```
## Specification
For a detailed explanation of the JSON5 format, please read the [official
specification](https://json5.github.io/json5-spec/).
## Installation
### Node.js
```sh
npm install json5
```
```js
const JSON5 = require('json5')
```
### Browsers
```html
<script src="https://unpkg.com/json5@^2.0.0/dist/index.min.js"></script>
```
This will create a global `JSON5` variable.
## API
The JSON5 API is compatible with the [JSON API].
[JSON API]:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON
### JSON5.parse()
Parses a JSON5 string, constructing the JavaScript value or object described by
the string. An optional reviver function can be provided to perform a
transformation on the resulting object before it is returned.
#### Syntax
JSON5.parse(text[, reviver])
#### Parameters
- `text`: The string to parse as JSON5.
- `reviver`: If a function, this prescribes how the value originally produced by
parsing is transformed, before being returned.
#### Return value
The object corresponding to the given JSON5 text.
### JSON5.stringify()
Converts a JavaScript value to a JSON5 string, optionally replacing values if a
replacer function is specified, or optionally including only the specified
properties if a replacer array is specified.
#### Syntax
JSON5.stringify(value[, replacer[, space]])
JSON5.stringify(value[, options])
#### Parameters
- `value`: The value to convert to a JSON5 string.
- `replacer`: A function that alters the behavior of the stringification
process, or an array of String and Number objects that serve as a whitelist
for selecting/filtering the properties of the value object to be included in
the JSON5 string. If this value is null or not provided, all properties of the
object are included in the resulting JSON5 string.
- `space`: A String or Number object that's used to insert white space into the
output JSON5 string for readability purposes. If this is a Number, it
indicates the number of space characters to use as white space; this number is
capped at 10 (if it is greater, the value is just 10). Values less than 1
indicate that no space should be used. If this is a String, the string (or the
first 10 characters of the string, if it's longer than that) is used as white
space. If this parameter is not provided (or is null), no white space is used.
If white space is used, trailing commas will be used in objects and arrays.
- `options`: An object with the following properties:
- `replacer`: Same as the `replacer` parameter.
- `space`: Same as the `space` parameter.
- `quote`: A String representing the quote character to use when serializing
strings.
#### Return value
A JSON5 string representing the value.
### Node.js `require()` JSON5 files
When using Node.js, you can `require()` JSON5 files by adding the following
statement.
```js
require('json5/lib/register')
```
Then you can load a JSON5 file with a Node.js `require()` statement. For
example:
```js
const config = require('./config.json5')
```
## CLI
Since JSON is more widely used than JSON5, this package includes a CLI for
converting JSON5 to JSON and for validating the syntax of JSON5 documents.
### Installation
```sh
npm install --global json5
```
### Usage
```sh
json5 [options] <file>
```
If `<file>` is not provided, then STDIN is used.
#### Options:
- `-s`, `--space`: The number of spaces to indent or `t` for tabs
- `-o`, `--out-file [file]`: Output to the specified file, otherwise STDOUT
- `-v`, `--validate`: Validate JSON5 but do not output JSON
- `-V`, `--version`: Output the version number
- `-h`, `--help`: Output usage information
## Contributing
### Development
```sh
git clone https://github.com/json5/json5
cd json5
npm install
```
When contributing code, please write relevant tests and run `npm test` and `npm
run lint` before submitting pull requests. Please use an editor that supports
[EditorConfig](http://editorconfig.org/).
### Issues
To report bugs or request features regarding the JSON5 data format, please
submit an issue to the [official specification
repository](https://github.com/json5/json5-spec).
To report bugs or request features regarding the JavaScript implementation of
JSON5, please submit an issue to this repository.
## License
MIT. See [LICENSE.md](./LICENSE.md) for details.
## Credits
[Assem Kishore](https://github.com/aseemk) founded this project.
[Michael Bolin](http://bolinfest.com/) independently arrived at and published
some of these same ideas with awesome explanations and detail. Recommended
reading: [Suggested Improvements to JSON](http://bolinfest.com/essays/json.html)
[Douglas Crockford](http://www.crockford.com/) of course designed and built
JSON, but his state machine diagrams on the [JSON website](http://json.org/), as
cheesy as it may sound, gave us motivation and confidence that building a new
parser to implement these ideas was within reach! The original
implementation of JSON5 was also modeled directly off of Dougs open-source
[json_parse.js] parser. Were grateful for that clean and well-documented
code.
[json_parse.js]:
https://github.com/douglascrockford/JSON-js/blob/03157639c7a7cddd2e9f032537f346f1a87c0f6d/json_parse.js
[Max Nanasy](https://github.com/MaxNanasy) has been an early and prolific
supporter, contributing multiple patches and ideas.
[Andrew Eisenberg](https://github.com/aeisenberg) contributed the original
`stringify` method.
[Jordan Tucker](https://github.com/jordanbtucker) has aligned JSON5 more closely
with ES5, wrote the official JSON5 specification, completely rewrote the
codebase from the ground up, and is actively maintaining this project.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,152 @@
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const pkg = require('../package.json')
const JSON5 = require('./')
const argv = parseArgs()
if (argv.version) {
version()
} else if (argv.help) {
usage()
} else {
const inFilename = argv.defaults[0]
let readStream
if (inFilename) {
readStream = fs.createReadStream(inFilename)
} else {
readStream = process.stdin
}
let json5 = ''
readStream.on('data', data => {
json5 += data
})
readStream.on('end', () => {
let space
if (argv.space === 't' || argv.space === 'tab') {
space = '\t'
} else {
space = Number(argv.space)
}
let value
try {
value = JSON5.parse(json5)
if (!argv.validate) {
const json = JSON.stringify(value, null, space)
let writeStream
// --convert is for backward compatibility with v0.5.1. If
// specified with <file> and not --out-file, then a file with
// the same name but with a .json extension will be written.
if (argv.convert && inFilename && !argv.outFile) {
const parsedFilename = path.parse(inFilename)
const outFilename = path.format(
Object.assign(
parsedFilename,
{base: path.basename(parsedFilename.base, parsedFilename.ext) + '.json'}
)
)
writeStream = fs.createWriteStream(outFilename)
} else if (argv.outFile) {
writeStream = fs.createWriteStream(argv.outFile)
} else {
writeStream = process.stdout
}
writeStream.write(json)
}
} catch (err) {
console.error(err.message)
process.exit(1)
}
})
}
function parseArgs () {
let convert
let space
let validate
let outFile
let version
let help
const defaults = []
const args = process.argv.slice(2)
for (let i = 0; i < args.length; i++) {
const arg = args[i]
switch (arg) {
case '--convert':
case '-c':
convert = true
break
case '--space':
case '-s':
space = args[++i]
break
case '--validate':
case '-v':
validate = true
break
case '--out-file':
case '-o':
outFile = args[++i]
break
case '--version':
case '-V':
version = true
break
case '--help':
case '-h':
help = true
break
default:
defaults.push(arg)
break
}
}
return {
convert,
space,
validate,
outFile,
version,
help,
defaults,
}
}
function version () {
console.log(pkg.version)
}
function usage () {
console.log(
`
Usage: json5 [options] <file>
If <file> is not provided, then STDIN is used.
Options:
-s, --space The number of spaces to indent or 't' for tabs
-o, --out-file [file] Output to the specified file, otherwise STDOUT
-v, --validate Validate JSON5 but do not output JSON
-V, --version Output the version number
-h, --help Output usage information`
)
}

View File

@@ -0,0 +1,4 @@
import parse = require('./parse')
import stringify = require('./stringify')
export {parse, stringify}

View File

@@ -0,0 +1,9 @@
const parse = require('./parse')
const stringify = require('./stringify')
const JSON5 = {
parse,
stringify,
}
module.exports = JSON5

View File

@@ -0,0 +1,15 @@
/**
* Parses a JSON5 string, constructing the JavaScript value or object described
* by the string.
* @template T The type of the return value.
* @param text The string to parse as JSON5.
* @param reviver A function that prescribes how the value originally produced
* by parsing is transformed before being returned.
* @returns The JavaScript value converted from the JSON5 string.
*/
declare function parse<T = any>(
text: string,
reviver?: ((this: any, key: string, value: any) => any) | null,
): T
export = parse

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,13 @@
const fs = require('fs')
const JSON5 = require('./')
// eslint-disable-next-line node/no-deprecated-api
require.extensions['.json5'] = function (module, filename) {
const content = fs.readFileSync(filename, 'utf8')
try {
module.exports = JSON5.parse(content)
} catch (err) {
err.message = filename + ': ' + err.message
throw err
}
}

View File

@@ -0,0 +1,4 @@
// This file is for backward compatibility with v0.5.1.
require('./register')
console.warn("'json5/require' is deprecated. Please use 'json5/register' instead.")

View File

@@ -0,0 +1,89 @@
declare type StringifyOptions = {
/**
* A function that alters the behavior of the stringification process, or an
* array of String and Number objects that serve as a allowlist for
* selecting/filtering the properties of the value object to be included in
* the JSON5 string. If this value is null or not provided, all properties
* of the object are included in the resulting JSON5 string.
*/
replacer?:
| ((this: any, key: string, value: any) => any)
| (string | number)[]
| null
/**
* A String or Number object that's used to insert white space into the
* output JSON5 string for readability purposes. If this is a Number, it
* indicates the number of space characters to use as white space; this
* number is capped at 10 (if it is greater, the value is just 10). Values
* less than 1 indicate that no space should be used. If this is a String,
* the string (or the first 10 characters of the string, if it's longer than
* that) is used as white space. If this parameter is not provided (or is
* null), no white space is used. If white space is used, trailing commas
* will be used in objects and arrays.
*/
space?: string | number | null
/**
* A String representing the quote character to use when serializing
* strings.
*/
quote?: string | null
}
/**
* Converts a JavaScript value to a JSON5 string.
* @param value The value to convert to a JSON5 string.
* @param replacer A function that alters the behavior of the stringification
* process. If this value is null or not provided, all properties of the object
* are included in the resulting JSON5 string.
* @param space A String or Number object that's used to insert white space into
* the output JSON5 string for readability purposes. If this is a Number, it
* indicates the number of space characters to use as white space; this number
* is capped at 10 (if it is greater, the value is just 10). Values less than 1
* indicate that no space should be used. If this is a String, the string (or
* the first 10 characters of the string, if it's longer than that) is used as
* white space. If this parameter is not provided (or is null), no white space
* is used. If white space is used, trailing commas will be used in objects and
* arrays.
* @returns The JSON5 string converted from the JavaScript value.
*/
declare function stringify(
value: any,
replacer?: ((this: any, key: string, value: any) => any) | null,
space?: string | number | null,
): string
/**
* Converts a JavaScript value to a JSON5 string.
* @param value The value to convert to a JSON5 string.
* @param replacer An array of String and Number objects that serve as a
* allowlist for selecting/filtering the properties of the value object to be
* included in the JSON5 string. If this value is null or not provided, all
* properties of the object are included in the resulting JSON5 string.
* @param space A String or Number object that's used to insert white space into
* the output JSON5 string for readability purposes. If this is a Number, it
* indicates the number of space characters to use as white space; this number
* is capped at 10 (if it is greater, the value is just 10). Values less than 1
* indicate that no space should be used. If this is a String, the string (or
* the first 10 characters of the string, if it's longer than that) is used as
* white space. If this parameter is not provided (or is null), no white space
* is used. If white space is used, trailing commas will be used in objects and
* arrays.
* @returns The JSON5 string converted from the JavaScript value.
*/
declare function stringify(
value: any,
replacer: (string | number)[],
space?: string | number | null,
): string
/**
* Converts a JavaScript value to a JSON5 string.
* @param value The value to convert to a JSON5 string.
* @param options An object specifying options.
* @returns The JSON5 string converted from the JavaScript value.
*/
declare function stringify(value: any, options: StringifyOptions): string
export = stringify

View File

@@ -0,0 +1,261 @@
const util = require('./util')
module.exports = function stringify (value, replacer, space) {
const stack = []
let indent = ''
let propertyList
let replacerFunc
let gap = ''
let quote
if (
replacer != null &&
typeof replacer === 'object' &&
!Array.isArray(replacer)
) {
space = replacer.space
quote = replacer.quote
replacer = replacer.replacer
}
if (typeof replacer === 'function') {
replacerFunc = replacer
} else if (Array.isArray(replacer)) {
propertyList = []
for (const v of replacer) {
let item
if (typeof v === 'string') {
item = v
} else if (
typeof v === 'number' ||
v instanceof String ||
v instanceof Number
) {
item = String(v)
}
if (item !== undefined && propertyList.indexOf(item) < 0) {
propertyList.push(item)
}
}
}
if (space instanceof Number) {
space = Number(space)
} else if (space instanceof String) {
space = String(space)
}
if (typeof space === 'number') {
if (space > 0) {
space = Math.min(10, Math.floor(space))
gap = ' '.substr(0, space)
}
} else if (typeof space === 'string') {
gap = space.substr(0, 10)
}
return serializeProperty('', {'': value})
function serializeProperty (key, holder) {
let value = holder[key]
if (value != null) {
if (typeof value.toJSON5 === 'function') {
value = value.toJSON5(key)
} else if (typeof value.toJSON === 'function') {
value = value.toJSON(key)
}
}
if (replacerFunc) {
value = replacerFunc.call(holder, key, value)
}
if (value instanceof Number) {
value = Number(value)
} else if (value instanceof String) {
value = String(value)
} else if (value instanceof Boolean) {
value = value.valueOf()
}
switch (value) {
case null: return 'null'
case true: return 'true'
case false: return 'false'
}
if (typeof value === 'string') {
return quoteString(value, false)
}
if (typeof value === 'number') {
return String(value)
}
if (typeof value === 'object') {
return Array.isArray(value) ? serializeArray(value) : serializeObject(value)
}
return undefined
}
function quoteString (value) {
const quotes = {
"'": 0.1,
'"': 0.2,
}
const replacements = {
"'": "\\'",
'"': '\\"',
'\\': '\\\\',
'\b': '\\b',
'\f': '\\f',
'\n': '\\n',
'\r': '\\r',
'\t': '\\t',
'\v': '\\v',
'\0': '\\0',
'\u2028': '\\u2028',
'\u2029': '\\u2029',
}
let product = ''
for (let i = 0; i < value.length; i++) {
const c = value[i]
switch (c) {
case "'":
case '"':
quotes[c]++
product += c
continue
case '\0':
if (util.isDigit(value[i + 1])) {
product += '\\x00'
continue
}
}
if (replacements[c]) {
product += replacements[c]
continue
}
if (c < ' ') {
let hexString = c.charCodeAt(0).toString(16)
product += '\\x' + ('00' + hexString).substring(hexString.length)
continue
}
product += c
}
const quoteChar = quote || Object.keys(quotes).reduce((a, b) => (quotes[a] < quotes[b]) ? a : b)
product = product.replace(new RegExp(quoteChar, 'g'), replacements[quoteChar])
return quoteChar + product + quoteChar
}
function serializeObject (value) {
if (stack.indexOf(value) >= 0) {
throw TypeError('Converting circular structure to JSON5')
}
stack.push(value)
let stepback = indent
indent = indent + gap
let keys = propertyList || Object.keys(value)
let partial = []
for (const key of keys) {
const propertyString = serializeProperty(key, value)
if (propertyString !== undefined) {
let member = serializeKey(key) + ':'
if (gap !== '') {
member += ' '
}
member += propertyString
partial.push(member)
}
}
let final
if (partial.length === 0) {
final = '{}'
} else {
let properties
if (gap === '') {
properties = partial.join(',')
final = '{' + properties + '}'
} else {
let separator = ',\n' + indent
properties = partial.join(separator)
final = '{\n' + indent + properties + ',\n' + stepback + '}'
}
}
stack.pop()
indent = stepback
return final
}
function serializeKey (key) {
if (key.length === 0) {
return quoteString(key, true)
}
const firstChar = String.fromCodePoint(key.codePointAt(0))
if (!util.isIdStartChar(firstChar)) {
return quoteString(key, true)
}
for (let i = firstChar.length; i < key.length; i++) {
if (!util.isIdContinueChar(String.fromCodePoint(key.codePointAt(i)))) {
return quoteString(key, true)
}
}
return key
}
function serializeArray (value) {
if (stack.indexOf(value) >= 0) {
throw TypeError('Converting circular structure to JSON5')
}
stack.push(value)
let stepback = indent
indent = indent + gap
let partial = []
for (let i = 0; i < value.length; i++) {
const propertyString = serializeProperty(String(i), value)
partial.push((propertyString !== undefined) ? propertyString : 'null')
}
let final
if (partial.length === 0) {
final = '[]'
} else {
if (gap === '') {
let properties = partial.join(',')
final = '[' + properties + ']'
} else {
let separator = ',\n' + indent
let properties = partial.join(separator)
final = '[\n' + indent + properties + ',\n' + stepback + ']'
}
}
stack.pop()
indent = stepback
return final
}
}

View File

@@ -0,0 +1,3 @@
export declare const Space_Separator: RegExp
export declare const ID_Start: RegExp
export declare const ID_Continue: RegExp

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,5 @@
export declare function isSpaceSeparator(c?: string): boolean
export declare function isIdStartChar(c?: string): boolean
export declare function isIdContinueChar(c?: string): boolean
export declare function isDigit(c?: string): boolean
export declare function isHexDigit(c?: string): boolean

View File

@@ -0,0 +1,35 @@
const unicode = require('../lib/unicode')
module.exports = {
isSpaceSeparator (c) {
return typeof c === 'string' && unicode.Space_Separator.test(c)
},
isIdStartChar (c) {
return typeof c === 'string' && (
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c === '$') || (c === '_') ||
unicode.ID_Start.test(c)
)
},
isIdContinueChar (c) {
return typeof c === 'string' && (
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
(c === '$') || (c === '_') ||
(c === '\u200C') || (c === '\u200D') ||
unicode.ID_Continue.test(c)
)
},
isDigit (c) {
return typeof c === 'string' && /[0-9]/.test(c)
},
isHexDigit (c) {
return typeof c === 'string' && /[0-9A-Fa-f]/.test(c)
},
}

View File

@@ -0,0 +1,109 @@
{
"_from": "json5@^2.2.1",
"_id": "json5@2.2.1",
"_inBundle": false,
"_integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==",
"_location": "/json5",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "json5@^2.2.1",
"name": "json5",
"escapedName": "json5",
"rawSpec": "^2.2.1",
"saveSpec": null,
"fetchSpec": "^2.2.1"
},
"_requiredBy": [
"#DEV:/",
"/@types/json5"
],
"_resolved": "https://registry.npmjs.org/json5/-/json5-2.2.1.tgz",
"_shasum": "655d50ed1e6f95ad1a3caababd2b0efda10b395c",
"_spec": "json5@^2.2.1",
"_where": "C:\\Git\\better-comments",
"author": {
"name": "Aseem Kishore",
"email": "aseem.kishore@gmail.com"
},
"bin": {
"json5": "lib/cli.js"
},
"browser": "dist/index.js",
"bugs": {
"url": "https://github.com/json5/json5/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "Max Nanasy",
"email": "max.nanasy@gmail.com"
},
{
"name": "Andrew Eisenberg",
"email": "andrew@eisenberg.as"
},
{
"name": "Jordan Tucker",
"email": "jordanbtucker@gmail.com"
}
],
"deprecated": false,
"description": "JSON for humans.",
"devDependencies": {
"core-js": "^2.6.5",
"eslint": "^5.15.3",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"regenerate": "^1.4.0",
"rollup": "^0.64.1",
"rollup-plugin-buble": "^0.19.6",
"rollup-plugin-commonjs": "^9.2.1",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-terser": "^1.0.1",
"sinon": "^6.3.5",
"tap": "^12.6.0",
"unicode-10.0.0": "^0.7.5"
},
"engines": {
"node": ">=6"
},
"files": [
"lib/",
"dist/"
],
"homepage": "http://json5.org/",
"keywords": [
"json",
"json5",
"es5",
"es2015",
"ecmascript"
],
"license": "MIT",
"main": "lib/index.js",
"module": "dist/index.mjs",
"name": "json5",
"repository": {
"type": "git",
"url": "git+https://github.com/json5/json5.git"
},
"scripts": {
"build": "rollup -c",
"build-package": "node build/package.js",
"build-unicode": "node build/unicode.js",
"coverage": "tap --coverage-report html test",
"lint": "eslint --fix .",
"prepublishOnly": "npm run production",
"preversion": "npm run production",
"production": "npm run lint && npm test && npm run build",
"test": "tap -Rspec --100 test",
"version": "npm run build-package && git add package.json5"
},
"types": "lib/index.d.ts",
"version": "2.2.1"
}

View File

@@ -0,0 +1,65 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Configuration = void 0;
const path = require("path");
const vscode = require("vscode");
const fs = require("fs");
const json5 = require("json5");
class Configuration {
/**
* Creates a new instance of the Parser class
*/
constructor() {
this.commentConfig = new Map();
this.languageConfigFiles = new Map();
this.UpdateLanguagesDefinitions();
}
/**
* Generate a map of configuration files by language as defined by extensions
* External extensions can override default configurations os VSCode
*/
UpdateLanguagesDefinitions() {
this.commentConfig.clear();
for (let extension of vscode.extensions.all) {
let packageJSON = extension.packageJSON;
if (packageJSON.contributes && packageJSON.contributes.languages) {
for (let language of packageJSON.contributes.languages) {
if (language.configuration) {
let configPath = path.join(extension.extensionPath, language.configuration);
this.languageConfigFiles.set(language.id, configPath);
}
}
}
}
}
/**
* Gets the configuration information for the specified language
* @param languageCode
* @returns
*/
GetCommentConfiguration(languageCode) {
// * check if the language config has already been loaded
if (this.commentConfig.has(languageCode)) {
return this.commentConfig.get(languageCode);
}
// * if no config exists for this language, back out and leave the language unsupported
if (!this.languageConfigFiles.has(languageCode)) {
return undefined;
}
try {
// Get the filepath from the map
let filePath = this.languageConfigFiles.get(languageCode);
let content = fs.readFileSync(filePath, { encoding: 'utf8' });
// use json5, because the config can contains comments
let config = json5.parse(content);
this.commentConfig.set(languageCode, config.comments);
return config.comments;
}
catch (error) {
this.commentConfig.set(languageCode, undefined);
return undefined;
}
}
}
exports.Configuration = Configuration;
//# sourceMappingURL=configuration.js.map

View File

@@ -0,0 +1,72 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deactivate = exports.activate = void 0;
const vscode = require("vscode");
const configuration_1 = require("./configuration");
const parser_1 = require("./parser");
// this method is called when vs code is activated
function activate(context) {
let activeEditor;
let configuration = new configuration_1.Configuration();
let parser = new parser_1.Parser(configuration);
// Called to handle events below
let updateDecorations = function () {
// if no active window is open, return
if (!activeEditor)
return;
// if lanugage isn't supported, return
if (!parser.supportedLanguage)
return;
// Finds the single line comments using the language comment delimiter
parser.FindSingleLineComments(activeEditor);
// Finds the multi line comments using the language comment delimiter
parser.FindBlockComments(activeEditor);
// Finds the jsdoc comments
parser.FindJSDocComments(activeEditor);
// Apply the styles set in the package.json
parser.ApplyDecorations(activeEditor);
};
// Get the active editor for the first time and initialise the regex
if (vscode.window.activeTextEditor) {
activeEditor = vscode.window.activeTextEditor;
// Set the regex patterns for the specified language's comments
parser.SetRegex(activeEditor.document.languageId);
// Trigger first update of decorators
triggerUpdateDecorations();
}
// * Handle extensions being added or removed
vscode.extensions.onDidChange(() => {
configuration.UpdateLanguagesDefinitions();
}, null, context.subscriptions);
// * Handle active file changed
vscode.window.onDidChangeActiveTextEditor(editor => {
if (editor) {
activeEditor = editor;
// Set regex for updated language
parser.SetRegex(editor.document.languageId);
// Trigger update to set decorations for newly active file
triggerUpdateDecorations();
}
}, null, context.subscriptions);
// * Handle file contents changed
vscode.workspace.onDidChangeTextDocument(event => {
// Trigger updates if the text was changed in the same document
if (activeEditor && event.document === activeEditor.document) {
triggerUpdateDecorations();
}
}, null, context.subscriptions);
// * IMPORTANT:
// * To avoid calling update too often,
// * set a timer for 100ms to wait before updating decorations
var timeout;
function triggerUpdateDecorations() {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(updateDecorations, 100);
}
}
exports.activate = activate;
function deactivate() { }
exports.deactivate = deactivate;
//# sourceMappingURL=extension.js.map

View File

@@ -0,0 +1,290 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Parser = void 0;
const vscode = require("vscode");
class Parser {
/**
* Creates a new instance of the Parser class
* @param configuration
*/
constructor(config) {
this.tags = [];
this.expression = "";
this.delimiter = "";
this.blockCommentStart = "";
this.blockCommentEnd = "";
this.highlightSingleLineComments = true;
this.highlightMultilineComments = false;
this.highlightJSDoc = false;
// * this will allow plaintext files to show comment highlighting if switched on
this.isPlainText = false;
// * this is used to prevent the first line of the file (specifically python) from coloring like other comments
this.ignoreFirstLine = false;
// * this is used to trigger the events when a supported language code is found
this.supportedLanguage = true;
// Read from the package.json
this.contributions = vscode.workspace.getConfiguration('better-comments');
this.configuration = config;
this.setTags();
}
/**
* Sets the regex to be used by the matcher based on the config specified in the package.json
* @param languageCode The short code of the current language
* https://code.visualstudio.com/docs/languages/identifiers
*/
SetRegex(languageCode) {
this.setDelimiter(languageCode);
// if the language isn't supported, we don't need to go any further
if (!this.supportedLanguage) {
return;
}
let characters = [];
for (let commentTag of this.tags) {
characters.push(commentTag.escapedTag);
}
if (this.isPlainText && this.contributions.highlightPlainText) {
// start by tying the regex to the first character in a line
this.expression = "(^)+([ \\t]*[ \\t]*)";
}
else {
// start by finding the delimiter (//, --, #, ') with optional spaces or tabs
this.expression = "(" + this.delimiter + ")+( |\t)*";
}
// Apply all configurable comment start tags
this.expression += "(";
this.expression += characters.join("|");
this.expression += ")+(.*)";
}
/**
* Finds all single line comments delimited by a given delimiter and matching tags specified in package.json
* @param activeEditor The active text editor containing the code document
*/
FindSingleLineComments(activeEditor) {
// If highlight single line comments is off, single line comments are not supported for this language
if (!this.highlightSingleLineComments)
return;
let text = activeEditor.document.getText();
// if it's plain text, we have to do mutliline regex to catch the start of the line with ^
let regexFlags = (this.isPlainText) ? "igm" : "ig";
let regEx = new RegExp(this.expression, regexFlags);
let match;
while (match = regEx.exec(text)) {
let startPos = activeEditor.document.positionAt(match.index);
let endPos = activeEditor.document.positionAt(match.index + match[0].length);
let range = { range: new vscode.Range(startPos, endPos) };
// Required to ignore the first line of .py files (#61)
if (this.ignoreFirstLine && startPos.line === 0 && startPos.character === 0) {
continue;
}
// Find which custom delimiter was used in order to add it to the collection
let matchTag = this.tags.find(item => item.tag.toLowerCase() === match[3].toLowerCase());
if (matchTag) {
matchTag.ranges.push(range);
}
}
}
/**
* Finds block comments as indicated by start and end delimiter
* @param activeEditor The active text editor containing the code document
*/
FindBlockComments(activeEditor) {
// If highlight multiline is off in package.json or doesn't apply to his language, return
if (!this.highlightMultilineComments)
return;
let text = activeEditor.document.getText();
// Build up regex matcher for custom delimiter tags
let characters = [];
for (let commentTag of this.tags) {
characters.push(commentTag.escapedTag);
}
// Combine custom delimiters and the rest of the comment block matcher
let commentMatchString = "(^)+([ \\t]*[ \\t]*)(";
commentMatchString += characters.join("|");
commentMatchString += ")([ ]*|[:])+([^*/][^\\r\\n]*)";
// Use start and end delimiters to find block comments
let regexString = "(^|[ \\t])(";
regexString += this.blockCommentStart;
regexString += "[\\s])+([\\s\\S]*?)(";
regexString += this.blockCommentEnd;
regexString += ")";
let regEx = new RegExp(regexString, "gm");
let commentRegEx = new RegExp(commentMatchString, "igm");
// Find the multiline comment block
let match;
while (match = regEx.exec(text)) {
let commentBlock = match[0];
// Find the line
let line;
while (line = commentRegEx.exec(commentBlock)) {
let startPos = activeEditor.document.positionAt(match.index + line.index + line[2].length);
let endPos = activeEditor.document.positionAt(match.index + line.index + line[0].length);
let range = { range: new vscode.Range(startPos, endPos) };
// Find which custom delimiter was used in order to add it to the collection
let matchString = line[3];
let matchTag = this.tags.find(item => item.tag.toLowerCase() === matchString.toLowerCase());
if (matchTag) {
matchTag.ranges.push(range);
}
}
}
}
/**
* Finds all multiline comments starting with "*"
* @param activeEditor The active text editor containing the code document
*/
FindJSDocComments(activeEditor) {
// If highlight multiline is off in package.json or doesn't apply to his language, return
if (!this.highlightMultilineComments && !this.highlightJSDoc)
return;
let text = activeEditor.document.getText();
// Build up regex matcher for custom delimiter tags
let characters = [];
for (let commentTag of this.tags) {
characters.push(commentTag.escapedTag);
}
// Combine custom delimiters and the rest of the comment block matcher
let commentMatchString = "(^)+([ \\t]*\\*[ \\t]*)("; // Highlight after leading *
let regEx = /(^|[ \t])(\/\*\*)+([\s\S]*?)(\*\/)/gm; // Find rows of comments matching pattern /** */
commentMatchString += characters.join("|");
commentMatchString += ")([ ]*|[:])+([^*/][^\\r\\n]*)";
let commentRegEx = new RegExp(commentMatchString, "igm");
// Find the multiline comment block
let match;
while (match = regEx.exec(text)) {
let commentBlock = match[0];
// Find the line
let line;
while (line = commentRegEx.exec(commentBlock)) {
let startPos = activeEditor.document.positionAt(match.index + line.index + line[2].length);
let endPos = activeEditor.document.positionAt(match.index + line.index + line[0].length);
let range = { range: new vscode.Range(startPos, endPos) };
// Find which custom delimiter was used in order to add it to the collection
let matchString = line[3];
let matchTag = this.tags.find(item => item.tag.toLowerCase() === matchString.toLowerCase());
if (matchTag) {
matchTag.ranges.push(range);
}
}
}
}
/**
* Apply decorations after finding all relevant comments
* @param activeEditor The active text editor containing the code document
*/
ApplyDecorations(activeEditor) {
for (let tag of this.tags) {
activeEditor.setDecorations(tag.decoration, tag.ranges);
// clear the ranges for the next pass
tag.ranges.length = 0;
}
}
//#region Private Methods
/**
* Sets the comment delimiter [//, #, --, '] of a given language
* @param languageCode The short code of the current language
* https://code.visualstudio.com/docs/languages/identifiers
*/
setDelimiter(languageCode) {
this.supportedLanguage = false;
this.ignoreFirstLine = false;
this.isPlainText = false;
const config = this.configuration.GetCommentConfiguration(languageCode);
if (config) {
let blockCommentStart = config.blockComment ? config.blockComment[0] : null;
let blockCommentEnd = config.blockComment ? config.blockComment[1] : null;
this.setCommentFormat(config.lineComment || blockCommentStart, blockCommentStart, blockCommentEnd);
this.supportedLanguage = true;
}
switch (languageCode) {
case "apex":
case "javascript":
case "javascriptreact":
case "typescript":
case "typescriptreact":
this.highlightJSDoc = true;
break;
case "elixir":
case "python":
case "tcl":
this.ignoreFirstLine = true;
break;
case "plaintext":
this.isPlainText = true;
// If highlight plaintext is enabled, this is a supported language
this.supportedLanguage = this.contributions.highlightPlainText;
break;
}
}
/**
* Sets the highlighting tags up for use by the parser
*/
setTags() {
let items = this.contributions.tags;
for (let item of items) {
let options = { color: item.color, backgroundColor: item.backgroundColor };
// ? the textDecoration is initialised to empty so we can concat a preceeding space on it
options.textDecoration = "";
if (item.strikethrough) {
options.textDecoration += "line-through";
}
if (item.underline) {
options.textDecoration += " underline";
}
if (item.bold) {
options.fontWeight = "bold";
}
if (item.italic) {
options.fontStyle = "italic";
}
let escapedSequence = item.tag.replace(/([()[{*+.$^\\|?])/g, '\\$1');
this.tags.push({
tag: item.tag,
escapedTag: escapedSequence.replace(/\//gi, "\\/"),
ranges: [],
decoration: vscode.window.createTextEditorDecorationType(options)
});
}
}
/**
* Escapes a given string for use in a regular expression
* @param input The input string to be escaped
* @returns {string} The escaped string
*/
escapeRegExp(input) {
return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
/**
* Set up the comment format for single and multiline highlighting
* @param singleLine The single line comment delimiter. If NULL, single line is not supported
* @param start The start delimiter for block comments
* @param end The end delimiter for block comments
*/
setCommentFormat(singleLine, start = null, end = null) {
this.delimiter = "";
this.blockCommentStart = "";
this.blockCommentEnd = "";
// If no single line comment delimiter is passed, single line comments are not supported
if (singleLine) {
if (typeof singleLine === 'string') {
this.delimiter = this.escapeRegExp(singleLine).replace(/\//ig, "\\/");
}
else if (singleLine.length > 0) {
// * if multiple delimiters are passed, the language has more than one single line comment format
var delimiters = singleLine
.map(s => this.escapeRegExp(s))
.join("|");
this.delimiter = delimiters;
}
}
else {
this.highlightSingleLineComments = false;
}
if (start && end) {
this.blockCommentStart = this.escapeRegExp(start);
this.blockCommentEnd = this.escapeRegExp(end);
this.highlightMultilineComments = this.contributions.multilineComments;
}
}
}
exports.Parser = Parser;
//# sourceMappingURL=parser.js.map

View File

@@ -0,0 +1,131 @@
{
"name": "better-comments",
"displayName": "Better Comments",
"icon": "icon.png",
"description": "Improve your code commenting by annotating with alert, informational, TODOs, and more!",
"version": "3.0.0",
"publisher": "aaron-bond",
"author": {
"name": "Aaron Bond"
},
"homepage": "https://github.com/aaron-bond/better-comments/blob/master/README.md",
"license": "SEE LICENSE IN LICENSE.md",
"repository": {
"type": "git",
"url": "https://github.com/aaron-bond/better-comments"
},
"bugs": "https://github.com/aaron-bond/better-comments/issues",
"categories": [
"Formatters"
],
"engines": {
"vscode": "^1.65.0"
},
"extensionKind": [
"ui",
"workspace"
],
"activationEvents": [
"onStartupFinished"
],
"galleryBanner": {
"color": "#e3f4ff",
"theme": "light"
},
"main": "./out/extension",
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"lint": "tslint -c tslint.json 'src/**/*.ts'"
},
"contributes": {
"configuration": {
"title": "Better Comments configuration",
"properties": {
"better-comments.multilineComments": {
"type": "boolean",
"description": "Whether the multiline comment highlighter should be active",
"default": true
},
"better-comments.highlightPlainText": {
"type": "boolean",
"description": "Whether the plaintext comment highlighter should be active",
"default": false
},
"better-comments.tags": {
"type": "array",
"description": "Tags which are used to color the comments. Changes require a restart of VS Code to take effect",
"default": [
{
"tag": "!",
"color": "#FF2D00",
"strikethrough": false,
"underline": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "?",
"color": "#3498DB",
"strikethrough": false,
"underline": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "//",
"color": "#474747",
"strikethrough": true,
"underline": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "todo",
"color": "#FF8C00",
"strikethrough": false,
"underline": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
},
{
"tag": "*",
"color": "#98C379",
"strikethrough": false,
"underline": false,
"backgroundColor": "transparent",
"bold": false,
"italic": false
}
]
}
}
}
},
"dependencies": {
"json5": "^2.2.1"
},
"devDependencies": {
"@types/json5": "^2.2.0",
"@types/vscode": "^1.65.0",
"@types/node": "^17.0.23",
"typescript": "^4.6.3",
"vsce": "^2.7.0",
"tslint": "^6.1.3"
},
"__metadata": {
"id": "7a0110bb-231a-4598-aa1b-0769ea46d28b",
"publisherId": "02145bab-b083-4d1e-b8ec-08d7abdd68da",
"publisherDisplayName": "Aaron Bond",
"targetPlatform": "undefined",
"updated": true,
"isPreReleaseVersion": false,
"preRelease": false,
"installedTimestamp": 1649320099217
}
}

View File

@@ -0,0 +1,18 @@
{
"rules": {
"no-string-throw": true,
"no-unused-expression": true,
"no-duplicate-variable": true,
"curly": [
true,
"ignore-same-line"
],
"class-name": true,
"semicolon": [
true,
"always"
],
"triple-equals": true
},
"defaultSeverity": "warning"
}