Skip to content

Commit

Permalink
BREAKING: rename the syncronous lintText method to lintTextSync
Browse files Browse the repository at this point in the history
Fixes: standard/standard#807

- BREAKING: rename the syncronous `lintText` method to `lintTextSync`
- Add an asyncronous `lintText` method (that just calls `lintTextSync`
internally)

This effectively undoes the breaking change introduced in 6.0.0, making
it safe to
upgrade from `standard-engine` 5.x to 7.x without introducing any
breaking changes.

Related: #156
  • Loading branch information
feross committed Apr 4, 2017
1 parent 0e8d7af commit 2b8e27a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## 7.0.0 - 2017-04-04

- BREAKING: rename the syncronous `lintText` method to `lintTextSync`
- Add an asyncronous `lintText` method (that just calls `lintTextSync` internally)

This effectively undoes the breaking change introduced in 6.0.0, making it safe to
upgrade from `standard-engine` 5.x to 7.x without introducing any breaking changes.

Related issues:

- https://github.com/feross/standard/issues/807
- https://github.com/Flet/standard-engine/issues/156

## 6.0.0 - 2017-02-20

- BREAKING: make `lintText` into a sync method
Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ The following options are provided in the `opts` object, and must be on the retu

## API Usage

### `results = standardEngine.lintText(text, [opts])`
### `engine.lintText(text, [opts], callback)`

Lint the provided source `text` to enforce your defined style. An `opts` object may
be provided:
Expand All @@ -261,7 +261,9 @@ be provided:

Additional options may be loaded from a `package.json` if it's found for the current working directory. See below for further details.

If an error occurs, an exception is thrown. Otherwise, a `results` object is returned:
The `callback` will be called with an `Error` and `results` object.

The `results` object will contain the following properties:

```js
{
Expand All @@ -281,7 +283,12 @@ If an error occurs, an exception is thrown. Otherwise, a `results` object is ret
}
```

### `standardEngine.lintFiles(files, [opts], callback)`
### `results = engine.lintTextSync(text, [opts])`

Synchronous version of `engine.lintText()`. If an error occurs, an exception is
thrown. Otherwise, a `results` object is returned.

### `engine.lintFiles(files, [opts], callback)`

Lint the provided `files` globs. An `opts` object may be provided:

Expand All @@ -303,6 +310,8 @@ Both `ignore` and `files` globs are resolved relative to the current working dir

The `callback` will be called with an `Error` and `results` object (same as above).

**NOTE: There is no synchronous version of `engine.lintFiles()`.**

### Full set of `opts`

This is the full set of options accepted by the above APIs. Not all options make sense for each API, for example `ignore` is not used with `lintText()`, and `filename` is not used with `lintFiles()`.
Expand Down
8 changes: 1 addition & 7 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,7 @@ Flags (advanced):
if (argv.stdin) {
getStdin().then(function (text) {
stdinText = text
var result
try {
result = standard.lintText(text, lintOpts)
} catch (err) {
return onResult(err)
}
onResult(null, result)
standard.lintText(text, lintOpts, onResult)
})
} else {
standard.lintFiles(argv._, lintOpts, onResult)
Expand Down
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,22 @@ function Linter (opts) {
* @param {string=} opts.parser custom js parser (e.g. babel-eslint)
* @param {string=} opts.filename path of the file containing the text being linted
*/
Linter.prototype.lintText = function (text, opts) {
Linter.prototype.lintTextSync = function (text, opts) {
opts = this.parseOpts(opts)
return new this.eslint.CLIEngine(opts.eslintConfig).executeOnText(text, opts.filename)
}

Linter.prototype.lintText = function (text, opts, cb) {
if (typeof opts === 'function') return this.lintText(text, null, opts)
var result
try {
result = this.lintTextSync(text, opts)
} catch (err) {
return process.nextTick(cb, err)
}
process.nextTick(cb, null, result)
}

/**
* Lint files to enforce JavaScript Style.
*
Expand Down
12 changes: 11 additions & 1 deletion test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@ test('api: lintFiles', function (t) {
})

test('api: lintText', function (t) {
t.plan(3)
var standard = getStandard()
standard.lintText('console.log("hi there")\n', function (err, result) {
t.error(err, 'no error while linting')
t.equal(typeof result, 'object', 'result is an object')
t.equal(result.errorCount, 1, 'should have used single quotes')
})
})

test('api: lintTextSync', function (t) {
t.plan(2)
var standard = getStandard()
var result = standard.lintText('console.log("hi there")\n')
var result = standard.lintTextSync('console.log("hi there")\n')
t.equal(typeof result, 'object', 'result is an object')
t.equal(result.errorCount, 1, 'should have used single quotes')
})
Expand Down

0 comments on commit 2b8e27a

Please sign in to comment.