3.0.2 • Published 5 years ago

@armirage/grunt-remove-js-comments v3.0.2

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
5 years ago

:earth_americas: :speech_balloon: English\ Table of Contents

 

@armirage/grunt-remove-js-comments    

GitHub tag (latest by date) GitHub issues Github code size GitHub license armirage-style liberapay-patrons

Choose between JSDocs, Multiline, Single line, Header lines, Comment Anchors, Marked comments, HTML type comments, or remove according to a RegEx pattern. This plugin offers that kind of delineated selection.

 

Table of Contents

About

Grunt 2 is a JavaScript task runner. It makes it easy to automate procedures. They have different plugins for different tasks. If a plugin does not exist, it is easy and quick to build a custom one.

If you are new to using Grunt, check out their "Getting Started" guide. It explains in detail how to install Grunt, use plugins, and create a Gruntfile.js.

This plugin allows you to select which comments (by syntax) to remove and which ones to leave untouched. If the list of options lack your specific case you can use a Regular Expression (RegEx) to match the code you want removed. (A very powerful overload feature.)

Install

Requires

To install Grunt and this plugin, run the following commands in the terminal:

npm install grunt @armirage/grunt-remove-js-comments --save-dev
  • :pencil: NOTE: The plugin is a scoped npm package and will need to be referenced that way.

This will save both as developer dependencies. Most likely this is for development and unnecessary in production builds.

While in the terminal, create the configuration file Gruntfile.js

touch Gruntfile.js
  • :pencil: NOTE: The capital "G".

To complete installation See Usage.

Usage

Once the grunt-remove-js-comments package is installed, you can configure the tasks to run in Gruntfile.js.

// Gruntfile.js

module.exports = function( grunt ) {

	grunt.initConfig({
		"remove-js-comments": {
			dev: {
				options: {
					removeJSDocs: true,
					removeMultilines: true,
					removeAnchors: true,
					removeSpecials: false,
					removeHeaderLines: true,
					removeDoubleSlashes: true,
					removeHTMLStyle: true,
					removeRegex: ""
				},
				src: "index.js",
				dest: "output.js",
				expand: false
			}
		},

		pkg: grunt.file.readJSON( "package.json" )
	});

	grunt.loadNpmTasks( "@armirage/grunt-remove-js-comments" );

	grunt.registerTask( "default", [ "remove-js-comments" ]);
};
  • :pencil: NOTE: The plugin is a scoped npm package and will need to be referenced that way.

Options

For information on passing options in a Gruntfile.js refer to Grunt's documentation: "Configuring Tasks".

* Any Option not listed in the Gruntfile.js will use its default value.

removeJSDocs

Type: Boolean Default value: false

JSDoc 3 is an API documentation generator for JavaScript, similar to Javadoc or phpDocumentor.

You add documentation comments directly to your source code, right alongside the code itself. The JSDoc tool will scan your source code and generate an HTML documentation website for you.

To learn more about JSDoc API Generation, visit the JSDoc Website.

To remove JSDocs comments, matching the following format, set to true.

/** inline JSDoc comment */

/**
 * @comment stuff be here
 */

removeMultilines

Type: Boolean Default value: false

To remove multiline comments, matching the following format, set to true.

/* inline comment using multiline syntax */

/*
 comments in here
 */
  • :pencil: NOTE: Set to true does not remove JSDocs, even though they are a type of multiline comment.

removeAnchors

Type: Boolean Default value: false

Comment Anchors 4 is a VS Code 5 extension.

Visually impaired programmers may have a challenge navigating the code base. Techniques such as indentation, line breaks, color coding of language keywords (such as IF-THEN), are all visual cues programmers use to scan and navigate to blocks of code. Signals that often are not communicated through assistive devices.

Comment Anchors scans and treats certain comments as hyperlinks in the code. Providing a textual navigation menu with links to code blocks.

To get Comment Anchors, download Comment Anchors from Visual Studio Marketplace

To remove Comment Anchors comments, matching the following format, set to true.

// ANCHOR link here

// FIXME A pesky bug.

// TODO One more thing etc..

removeSpecials

Type: Boolean Default value: false

To remove special comments, matching the following format, set to true.

/*! Author: Nathaniel Hawthorne !*\

/*# Let's not lose this. 
  • :pencil: NOTE: Many libraries put attribution info in these types comments. If you do not completely own all of the code, consider leaving this option default for attribution and copyright purposes.

removeHeaderLines

Type: Boolean Default value: false

To remove header line comments, matching the following format, set to true.

//---------

//=========

//-+-+-+-+-+

removeDoubleSlashes

Type: Boolean Default value: false

To remove double slash comments, matching the following format, set to true.

// only one line, can not go any further.
  • :pencil: NOTE: Set to true does not remove Comment Anchors, specials, or header lines, even though they are a type of single line, double slash comment.

removeHTMLStyle

Type: Boolean Default value: false

While grunt-remove-js-comments is intended towards and tested against JavaScript files. I have found it safe to use for my whole project. I use it on HTML, CSS, XML, and other file types. The removals are CSS url safe.

To remove HTML comments, matching the following format, set to true.

<!-- comment be in here -->

removeRegex

Type: string Default value: ""

"Regex" colloquially refers to RegExp or Regular Expressions. A regular expression is an object that describes a pattern of characters.

Regular expressions are used to perform pattern-matching and "search-and-replace" functions on text.

To learn more about JavaScript Regular Expression, refer to the W3C Schools website.

To remove code matching a Regular Expression, set this option to a "regex" string.

Example "Setting the removeRegex Option": // Gruntfile.js excerpt

...
options: {
	removeRegex: "/^[\t\s]*(\/\/)\s*T\d{2}:\d{2}:\d{2}Z/gm"
}
...

Would remove all lines matching that pattern, such as the example below:

// 2015-12-22T17:44:24Z
  • :warning: WARNING: This will remove anything matching the expression. It is not limited to comment lines.

How to Contribute

Review the Contributing Guidelines for ways to make this repository better.

Open Source Software (OSS) is only as strong as our Community.

  Thank you!

Acknowledgements

Grunt is easy and extensible. Integrates well into production Continuos Integration (CI) processes. Cheers to them!

Inspired by echoloyuk's original code for grunt-remove-comments.

Contact

Armirage Github repositories and @armirage scoped NPM modules are maintained by Armirage, A Technology Solutions company, feel free to contact us!

Release History

  • 2020-09-30 Breaking change reversed Logic to explicitly remove things. Update to Armirage style.
  • 2020-09-18 Breaking change JSdocs to JSDoc, and added Regex Expressions.
  • 2020-09-16 Begin

Footnotes

1: "Sticky Note Lot" by Min An, licensed under Pexels :arrow_heading_up:

2: Grunt: The JavaScript Task Runner https://gruntjs.com/ accessed 30 September 2020(#anchor-2)

3: @Use JSDoc https://jsdoc.app/index.html/ accessed 30 September 2020(#anchor-3)

4: Comment Anchors - Exodius Studios https://marketplace.visualstudio.com/items?itemName=ExodiusStudios.comment-anchors/ accessed 30 September 2020(#anchor-4)

5: Visual Studio Code https://code.visualstudio.com/ accessed 30 September 2020(#anchor-5)

 

 

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.6

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago