0.1.1 • Published 7 years ago

formatting-test v0.1.1

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

formatting-test

THIS PACKAGE IS NO LONGER MAINTAINED

The formatting-test npm package helps JS developers test that their code meets certain formatting conventions. You can enable and disable rules as you choose, but you can't define your own rules. If you'd like to add any rules or functionality, I'm happy to accept PRs!

Installation

  1. Install the package
npm install -D mocha # if it's not already installed
npm install -D formatting-test
  1. Create formatting-test.js
const FormattingTest = require('./app');

new FormattingTest()
    .useAll() // by default, no rules are enabled
    .exec();
  1. Create an npm script (in package.json)
...
scripts: {
   "test-formatting": "mocha --reporter spec formatting-test.js",
},
...
  1. Run it
npm run test-formatting

Configuration

Enabling and disabling rules

By default, no rules are enabled. It's up to you to opt in to the rules you want to use. Alternatively, you can opt in to all rules and then out of any that you don't like.

Opting out of all rules (default behaviour, unless you've somehow overridden it)

new FormattingTest()
    .dontUseAll()
    .exec();

Opting in to all rules

new FormattingTest()
    .useAll()
    .exec();

Opting in to specific rules

new FormattingTest()
    .use(ruleName) // e.g. ruleName = 'dotConstructorIsNotUsed'
    .exec();

Opting out of specific rules

new FormattingTest()
    .useAll()
    .dontUse(ruleName) // e.g. ruleName = 'exportHasSameNameAsModule'
    .exec();

Rules

  • dotConstructorIsNotUsed: Ensures that "this.constructor" is not found anywhere in application or test files.
  • exportHasSameNameAsModule: Validates (for application files only) the export name. Exactly one of the following must be true: (1) The export name is the same as the file name (not including .js extension), or (2) The export name is the same as the containing folder name, and the file name is index.js.
  • importsDoNotEndWithExtension: Ensures that imports (require()) do not use file extensions. Use "foo" or "./bar/baz" instead of "foo.js" or "./bar/baz".
  • importsDoNotUseIndexIdentifier: Ensures that imports (require()) do not use /index in the oath. Use ./bar/baz instead of ./bar/baz/index.
  • oneClassExportedPerFile: Ensures that there is exactly one export (class or function) per file.
0.1.1

7 years ago

0.1.0

7 years ago