Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Creating a Custom Preset or Config

Adonis K edited this page Dec 18, 2015 · 8 revisions

Custom Presets

For regular projects, using the built-in preset/config such as the airbnb, google, or jquery preset may be good enough. However, it may be more useful to share your config files across your company's projects or your own ecosystem of projects.

You can either create an npm package to share, or just link to a local file. Check out npm for examples.

Creating the Config

The shared config file itself doesn't need to change. It is just a regular .jscs.json or .jscsrc file.

Creating the Package

You will need to publish a npm package with your config file (.jscs.json or .jscsrc) as the main file.

It's recommended that the package name starts with jscs-preset- or with jscs-config- to help with searching for presets on npm and as well as making it easier to use in your configs; e.g. "preset": "awesome" instead of "preset": "jscs-preset-awesome".

You can also share multiple presets in one package and use them like ”preset”: “awesome/super-awesome”, provided that you have super-awesome.{json, js} in your package root directory.

// example package.json in `jscs-config-awesome`
{
  “name”: “jscs-config-awesome”, // or "jscs-preset-awesome"
  “version”: “1.0.0,
  “main”: “jscs.json” // or ".jscsrc"
}

Then you can publish your package on npm and start using it in your projects.

Using a Config

You can use it like any other built-in preset.

// example .jscsrc using a custom preset
// assuming the preset package name is `jscs-config-awesome`
{
  "preset": "awesome",
  "disallowEmptyBlocks": false // an example of disabling a preset rule with false
  "disallowArrowFunctions": null // an example of disabling a preset rule with null
  "disallowCapitalizedComments": null // you can also just null a rule to label it for later
}

Just make sure that your package is installed:

// package.json
{
  "devDependencies": {
    "jscs": "2.2.1",
    "jscs-config-awesome": "1.0.0"
  }
}

Have fun making your own configs!