1.0.1 • Published 7 years ago

testlint v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

testlint

A helping hand in releasing reliable world-class ESLint plugins & presets

Usage with Tape

Add this to your dependencies block of package.json:

"eslint": "^4.2.0",
"tape": "^4.6.3",
"tap-difflet": "0.7.0",

Run npm i testlint

Create your own lint test function with testlint like so:

const createTestLint = require('testlint')

const reactSpecificESLintConfig = {
  plugins: [ 'react' ],
  parserOptions: {
    ecmaFeatures: {
      jsx: true
    }
  }
}

const baseESLintConfig = {
  useEslintrc: false,
  // Point to the ESLint config you're building & testing here
  configFile: 'eslintrc.json'
}

const cliEngineOptionsCreator = ({ withReactSupport = false } = { }) =>  
  [
    baseESLintConfig,
    withReactSupport ? reactSpecificESLintConfig : { }
  ]

module.exports = createTestLint(cliEngineOptionsCreator)

Using your ESLint preset/config tester in your /test folder like so:

const testLint = require('../my-testlint')

testLint('load config in eslint to validate all rule syntax is correct', 
  'const foo = 1\nconst bar = function () { return \'bar\' }\nbar(foo)\n',
  (execution, t) => {
    t.equal(execution.errorCount, 0)
    t.end()
  })

testLint('JSX props should be found no more than once per component', 
  `
const Foo = props => <div {...props} />
Foo.displayName = 'foo-young'
const foo = Foo.displayName
const bar = function (myName) {
  return <Foo myName={myName} myName={myName} />
}
module.exports = bar(foo)\n`,
  { withReactSupport : true },
  (execution, t) => {
    t.equal(execution.errorCount, 1)
    t.equal(execution.results[0].messages[0].ruleId, 'react/jsx-no-duplicate-props')

    t.end()
  })

Then run: node --harmony ./node_modules/.bin/tape test/*.js | tap-difflet