npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-happiness

v2.0.2

Published

Gulp plugin for happiness

Downloads

11

Readme

gulp-happiness

npm es2015 license Build Status Dependencies

Gulp plugin for happiness

js-happiness-style


Installing

npm install --save gulp-happiness
# or using yarn cli
yarn add gulp-happiness

Usage

Check out files with happiness linter

const gulp = require('gulp');
const gulpHappiness = require('gulp-happiness');

gulp.task('lint', function () {
	return gulp.src(['**/*.js','!node_modules/**'])
		// Attaches the lint data to the "eslint" property
		// of the file object so it can be used by other modules. 
		// By default it will skip files with empty content
		// and if filename starts with _ (underscore)
		.pipe(gulpHappiness())
		
		// eslint.format() outputs the lint results to the console.
		.pipe(gulpHappiness.format())
		
		// Look after checking all the streamed files,
		// and if at least one of them has errors it will fail.
		// Note! This method does not transfer files further to the stream!
		.pipe(gulpHappiness.failAfterError());
});

Lint files, fix and transfer

const gulp = require('gulp');
const gulpHappiness = require('gulp-happiness');

gulp.task('lint', function () {
	return gulp.src('./src/scripts/**/*.js')
		// Enable fixing - fix: true.
		// If auto fixing cannot be done, 
		// you will see message in console about it
		.pipe(gulpHappiness({
			fix: true
		}))
		
		// Show in console happy files ;)
		.pipe(gulpHappiness.format({
			showHappyFiles: true
		}))
		
		// Failing if file has eslint errors,
		// it will break task immediately.
		// Current file and all next not will be transferred
		.pipe(gulpHappiness.failOnError())
		
		// transfer files
		.pipe(gulp.dest('./dist/assets/js/'));
});

API

gulpHappiness()

No explicit configuration.
Linting with default options.
Attaches the lint data to the "eslint" property of the file object so it can be used by other modules.

gulpHappiness(options)

options.fix

type boolean / default undefined
Fix most issues automatically if set true.

Note! It will not fix original files in your fs.
It will fix files in stream and you must save them where you need by using gulp.dest() after linting

Note! If auto fixing cannot be done - you will see message in console about it.
Example of log:

Cannot auto fix example

options.linterOptions

type Object / default undefined
Options for happiness linter

options.linterOptions.globals

type Array.<string> / default undefined
Custom global variables to declare (e.g. ['jquery', '$'])

options.linterOptions.plugins

type Array.<string> / default undefined
Custom eslint plugins

options.linterOptions.envs

type Array.<string> / default undefined
Custom eslint environment

options.linterOptions.parser

type string / default undefined
Custom js parser (e.g. 'babel-eslint')

options.noUnderscore

type boolean / default true
File which name starts with _ (underscore) will be skipped and not using in stream next.

You will receive message in console if it happens.
Example of log:

no-empty log example

options.noEmpty

type boolean / default true
File with empty content will be skipped and not using in stream next.
Note! Spaces, tabs and newlines will be treated as empty content.

You will receive message in console if it happens.
Example of log:

no-empty log example

options.silent

type boolean / default undefined
No logs about noEmpty and noUnderscore files

gulpHappiness.format()

No explicit configuration.
Outputs the lint results to the console.
Default formatter is eslint-formatter-pretty

gulpHappiness.format(formatterName)

formatterName

type string
You can use formatter by default
gulpHappiness.format('default') - same as gulpHappiness.format()

or use one of the ESLint-provided formatters,
for example gulpHappiness.format('stylish')

or use some else formatter which you can install from npm https://www.npmjs.com/search?q=eslint+formatter
Example

npm i --save eslint-friendly-formatter
const gulp = require('gulp');
const gulpHappiness = require('gulp-happiness');

gulp.task('lint', function () {
	return gulp.src(['**/*.js','!node_modules/**'])
		.pipe(gulpHappiness())
		.pipe(gulpHappiness.format('eslint-friendly-formatter'))
});

gulpHappiness.format(formatterFunction)

formatterFunction(results[, formatterOptions])

type function

Parameters:

Name | Data type | Description --- | --- | --- results | Array | Results of eslint formatterOptions | Object/undefined | Options for formatter

You can use own function or existing formatters as function https://www.npmjs.com/search?q=eslint+formatter

Note! Function will receive results array from eslint data for formatting.
And it is must return output as string if has problems in received results for console or some negative value, e.g. null | undefined | false | '' .

Example with custom formatter function

const gulp = require('gulp');
const gulpHappiness = require('gulp-happiness');

gulp.task('lint', function () {
	return gulp.src(['**/*.js','!node_modules/**'])
		.pipe(gulpHappiness())
		.pipe(gulpHappiness.format(function(results, formatterOptions={}) {
			// process results and options
			// ...
			
			let output = myOwnMethodForTransformResults(results, transformOptions);
			
			return output;
		}))
});

Example with installed formatter function

npm i --save eslint-friendly-formatter
const gulp = require('gulp');
const gulpHappiness = require('gulp-happiness');
const eslintFriendlyFormatter = require('eslint-friendly-formatter');

gulp.task('lint', function () {
	return gulp.src(['**/*.js','!node_modules/**'])
		.pipe(gulpHappiness())
		.pipe(gulpHappiness.format(eslintFriendlyFormatter))
});

gulpHappiness.format(formatterName/formatterFunction, options)

formatterName/formatterFunction

see above formatterName and formatterFunction

options.formatterOptions

type Object / default undefined
Options for the chosen formatter

options.showHappyFiles

type boolean / default undefined
Show files without problems in console

Example of log:

Show happy files example

options.noUnderscore

Same as gulpHappiness(options) → options.noUnderscore

options.noEmpty

Same as gulpHappiness(options) → options.noEmpty

options.silent

Same as gulpHappiness(options) → options.silent

gulpHappiness.failOnError()

No explicit configuration.

gulpHappiness.failOnError(options)

options.disabled

type boolean / default undefined
Not fail on errors

options.onEnd(errorMsg, eslintData)

type fucnction / default undefined

Parameters:

Name | Data type | Description --- | --- | --- errorMsg | null/string | Is null if no errors were found and is string if errors were found. String contains a short message about errors eslintData | Object | eslint data from file

Its call will be before ending of pipe. So you don't need apply no callbacks or return some values.
You can use it for own custom actions, e.g rewrite some globals.
Note! Even if options.disabled - is true - this function will be called

options.noUnderscore

Same as gulpHappiness(options) → options.noUnderscore

options.noEmpty

Same as gulpHappiness(options) → options.noEmpty

options.silent

Same as gulpHappiness(options) → options.silent

gulpHappiness.failAfterError()

No explicit configuration.

gulpHappiness.failAfterError(options)

options.disabled

Same as gulpHappiness.failOnError(options) → options.disabled

options.onEnd(errorMsg, errorFilesPaths, allErrorsCount)

type fucnction / default undefined

Parameters:

Name | Data type | Description --- | --- | --- errorMsg | null/string | Is null if no errors were found and is string if errors were found. String contains a short message about errors errorFilesPaths | Array | Array of files with errors. It will an empty if no files. allErrorsCount | number | Count of all errors. Will be 0 if no errors

Its call will be before ending of pipe. So you don't need apply no callbacks or return some values.
You can use it for own custom actions, e.g rewrite some globals.
Note! Even if options.disabled - is true - this function will be called

options.noUnderscore

Same as gulpHappiness(options) → options.noUnderscore

options.noEmpty

Same as gulpHappiness(options) → options.noEmpty

options.silent

Same as gulpHappiness(options) → options.silent

Tests

  1. npm test for testing code style and run mocha tests
  2. npm run happiness-fix for automatically fix most of problems with code style

Changelog

Please read CHANGELOG.md

Contributing

Please read CONTRIBUTING.md