GithubHelp home page GithubHelp logo

johankj / grunt-lintspaces Goto Github PK

View Code? Open in Web Editor NEW

This project forked from schorfes/grunt-lintspaces

0.0 1.0 0.0 170 KB

A Grunt task for checking spaces in files.

License: MIT License

JavaScript 99.03% Python 0.97%

grunt-lintspaces's Introduction

#grunt-lintspaces

A Grunt task for checking spaces in files depending on the node module lintspaces.

If you're looking for a gulpjs task to validate your files, take a look at this one:

Issues & feature requests

This grunt task is just a wrapper for the node module called lintspaces. If you have any issues or feature requests, please consider if this may belongs to the node module its self.

Getting Started

If you haven't used grunt before, be sure to check out the Getting Started guide.

From the same directory as your project's Gruntfile and package.json, install this plugin with the following command:

npm install grunt-lintspaces --save-dev

Once that's done, add this line to your project's Gruntfile:

grunt.loadNpmTasks('grunt-lintspaces');

Inside your grunt.js file add a section named lintspaces. This section specifies the tasks. Each task takes sources and options as parameters.

Parameters

sources src

This sets the path of the files to be checked.

Options

newline at end of file option

Tests for newlines at the end of all files. Default value is false.

	newline: true
  • returns code NEWLINE, when a missing a newline at the end of the file.
  • returns code NEWLINE_AMOUNT, when found unexpected additional newlines at the end of a file.
  • returns type warning

maximum newlines option

Test for the maximum amount of newlines between code blocks. Default value is false. To enable this validation a number larger than 0 is expected.

	newlineMaximum: 2
  • returns code NEWLINE_MAXIMUM, when maximum amount of newlines exceeded between code blocks.
  • returns type warning

trailingspaces option

Tests for useless whitespaces (trailing whitespaces) at each lineending of all files. Default value is false.

	trailingspaces: true
  • returns code TRAILINGSPACES, when unexpected trailing spaces were found.
  • returns type warning

Note: If you like to to skip empty lines from reporting (for whatever reason), use the option trailingspacesSkipBlanks and set them to true.

indentation options

Tests for correct indentation using tabs or spaces. Default value is false. To enable indentation check use the value 'tabs' or 'spaces'.

	indentation: 'tabs'
  • returns code INDENTATION_TABS, when spaces are used instead of tabs.
  • returns type warning

If the indentation option is set to 'spaces', there is also the possibility to set the amount of spaces per indentation using the spaces option. Default value is 4.

	indentation: 'spaces',
	spaces: 2
  • returns code INDENTATION_SPACES, when tabs are used instead of spaces.
  • returns code INDENTATION_SPACES_AMOUNT, when spaces are used but the amound is not as expected.
  • returns type warning

guess indentation option

This indentationGuess option tries to guess the indention of a line depending on previous lines. The report of this option can be incorrect, because the correct indentation depends on the actual programming language and styleguide of the certain file. The default value is false - disabled.

This feature follows the following rules: The indentation of the current line is correct when:

  • the amount of indentations is equal to the previous or
  • the amount of indentations is less than the previous line or
  • the amount of indentations is one more than the previous line
  • the amount of indentations is zero and the lines length is also zero which is an empty line without trailing whitespaces
	indentationGuess: true
  • returns code NEWLINE_GUESS
  • returns type hint

ignores option

Use the ignores option when special lines such as comments should be ignored. Provide an array of regular expressions to the ignores property.

	ignores: [
		/\/\*[\s\S]*?\*\//g,
		/foo bar/g
	]

There are some build in ignores for comments which you can apply by using these strings:

  • 'js-comments'
  • 'c-comments'
  • 'java-comments'
  • 'as-comments'
  • 'xml-comments'
  • 'html-comments'
  • 'python-comments'
  • 'ruby-comments'
  • 'applescript-comments'

(build in strings and userdefined regular expressions are mixable in the ignores array)

	ignores: [
		'js-comments',
		/foo bar/g
	]

Feel free to contribute some new regular expressions as build in!

Note: Trailing spaces are not ignored by default, because they are always evil!! If you still want to ignore them use the trailingspacesToIgnores option and set them to true.

.editorconfig option

It's possible to overwrite the default and given options by setting up a path to an external editorconfig file by unsing the editorconfigoption. For a basic configuration of a .editorconfig file check out the EditorConfig Documentation.

	editorconfig: '.editorconfig'

The following .editorconfig values are supported:

  • insert_final_newline will check if a newline is set
  • indent_style will check the indentation
  • indent_size will check the amount of spaces
  • trim_trailing_whitespace will check for useless whitespaces

showValid option

This is a specific option related to this task. When active all valid processed files will be logged. Default value is false.

	showValid: true

showTypes option

This is a specific option related to this task. By default the type of each message is shown by the color of the message text. To show at the beginning of the message set this to true. Default value is false.

	showTypes: true

showCodes option

This is a specific option related to this task. When active all reporting codes will appear at the end of each message. Default value is false.

	showCodes: true

Configuration Examples

lintspaces: {
	all: {
		src: [
			'**/*'
		],
		options: {
			newline: true,
			newlineMaximum: 2,
			trailingspaces: true,
			indentation: 'spaces',
			spaces: 2
		}
	},
	javascript: {
		src: [
			'js/src/**/*.js'
		],
		options: {
			newline: true,
			trailingspaces: true,
			indentation: 'tabs',
			ignores: ['js-comments']
		}
	},
	external: {
		src: [
			'**/*'
		],
		options: {
			editorconfig: '.editorconfig'
		}
	}
}

Contribution

Tests & Validation

Run grunt to lint and run the tests.

License

LICENSE (MIT)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.