This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 510
Creating a New Rule
Joel Kemp edited this page Oct 6, 2015
·
3 revisions
This is a new contributors guide to writing new rules and submitting them as contributions to JSCS:
Feel free to submit a work in progress PR and ask for feedback or help with ASTs or our APIs. It can be difficult when first learning about ASTs but it picks up quickly!
Check out CONTRIBUTING.md as well!
-
lib/rules
has rules with hyphen separated file names. For example:disallow-anonymous-functions.js
. Each rule is accompanied by JS doc style documentation at the beginning which is used on the website, e.g. http://jscs.info/rule/disallowAnonymousFunctions. -
test/specs/rules
contains tests for each rule, one per file. - JSCS uses mocha to run its tests.
- To test out your new rule, type
npm test
and make sure there are no errors with the tests you wrote (this runs jshint/jscs as well as unit tests).- You can also run a specific subset of rules with
-g
, e.g.mocha -g "disallow-anonymous-functions"
ormocha -g "#1831"
- You can also run a specific subset of rules with
Definitely check out the existing rules for conventions/help or look for and older PR that starts with
New Rule: newRuleHere
. Using a tool like http://astexplorer.net/ is recommended.
- Make a rule implementation like
lib/rules/awesome-new-rule.js
. - Register the rule in the
registerDefaultRules
method ofStringChecker
(lib/string-checker.js).this.registerRule(require('../rules/awesome-new-rule'));
- Add your rule's tests like
test/specs/rules/awesome-new-rule.js
- Add your rule to a group in
grouping.json
(If you don't know just add it to the last group).