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

cslint-loader

v1.0.0

Published

coffeelint loader for webpack v2(+)

Downloads

4

Readme

cslint-loader

coffeelint loader for webpack v2(+)

Install

$ npm install cslint-loader --save-dev

Usage

In your webpack configuration

module.exports = {
  // ...
  module: {
    rules: [
      {
        enforce: "pre",
        test: /\.coffee$/,
        exclude: /node_modules/,
        loader: "cslint-loader",
        options: {
          // cslint options (if necessary)
        }
      },
    ],
  },
  // ...
}

Options

You can pass eslint options using standard webpack loader options.

Note that the config option you provide will be passed to the CLIEngine. This is a different set of options than what you'd specify in package.json or .eslintrc. See the eslint docs for more detail.

fix (default: false)

This option will enable ESLint autofix feature.

Be careful: this option might cause webpack to enter an infinite build loop if some issues cannot be fixed properly.

cache (default: false)

This option will enable caching of the linting results into a file. This is particularly useful in reducing linting time when doing a full build.

The cache file is written to the ./node_modules/.cache directory.

formatter (default: eslint stylish formatter)

Loader accepts a function that will have one argument: an array of eslint messages (object). The function must return the output as a string. You can use official eslint formatters.

module.exports = {
  entry: "...",
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: "cslint-loader",
        options: {
          // several examples !

          // default value
          formatter: require("eslint/lib/formatters/stylish"),

          // community formatter
          formatter: require("eslint-friendly-formatter"),

          // custom formatter
          formatter: function(results) {
            // `results` format is available here
            // http://eslint.org/docs/developer-guide/nodejs-api.html#executeonfiles()

            // you should return a string
            // DO NOT USE console.*() directly !
            return "OUTPUT"
          }
        }
      },
    ],
  },
}

eslintPath (default: "eslint")

Path to eslint instance that will be used for linting.

module.exports = {
  entry: "...",
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: "cslint-loader",
        options: {
          eslintPath: path.join(__dirname, "reusable-eslint-rules.js"),
        }
      },
    ],
  },
  }

Errors and Warning

By default the loader will auto adjust error reporting depending on eslint errors/warnings counts. You can still force this behavior by using emitError or emitWarning options:

emitError (default: false)

Loader will always return errors if this option is set to true.

module.exports = {
  entry: "...",
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: "cslint-loader",
        options: {
          emitError: true,
        }
      },
    ],
  },
}
emitWarning (default: false)

Loader will always return warnings if option is set to true.

quiet (default: false)

Loader will process and report errors only and ignore warnings if this option is set to true

module.exports = {
  entry: "...",
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: "cslint-loader",
        options: {
          quiet: true,
        }
      },
    ],
  },
}
failOnWarning (default: false)

Loader will cause the module build to fail if there are any eslint warnings.

module.exports = {
  entry: "...",
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: "cslint-loader",
        options: {
          failOnWarning: true,
        }
      },
    ],
  },
}
failOnError (default: false)

Loader will cause the module build to fail if there are any eslint errors.

module.exports = {
  entry: "...",
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: "cslint-loader",
        options: {
          failOnError: true,
        }
      },
    ],
  },
}
outputReport (default: false)

Write the output of the errors to a file, for example a checkstyle xml file for use for reporting on Jenkins CI

The filePath is relative to the webpack config: output.path You can pass in a different formatter for the output file, if none is passed in the default/configured formatter will be used

module.exports = {
  entry: "...",
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: "cslint-loader",
        options: {
          outputReport: {
            filePath: 'checkstyle.xml',
            formatter: require('eslint/lib/formatters/checkstyle')
          }
        }
      },
    ],
  },
}

Gotchas

NoErrorsPlugin

NoErrorsPlugin prevents webpack from outputting anything into a bundle. So even ESLint warnings will fail the build. No matter what error settings are used for cslint-loader.

So if you want to see ESLint warnings in console during development using WebpackDevServer remove NoErrorsPlugin from webpack config.

Defining configFile or using eslint -c path/.eslintrc

Bear in mind that when you define configFile, eslint doesn't automatically look for .eslintrc files in the directory of the file to be linted. More information is available in official eslint documentation in section Using Configuration Files. See #129.


Changelog

License