Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

atom-linter

steelbrain202MIT10.0.0

Helper module for atom linter providers

atom, linter

readme

atom-linter

Greenkeeper badge

atom-linter is an npm helper module that you can import in your Linter Providers and make things easier for yourself.

API

For full documentation of exec and execNode API, please refer to sb-exec README

export const FindCache: Map
export function exec(command: String, args: Array<string> = [], options: Object): Promise
export function execNode(filePath: String, args: Array<string> = [], options: Object): Promise
export function parse(data: String, regex: String, options: Object = {flags: 'g'}): Array<Linter$Message>
export function generateRange(textEditor: TextEditor, lineNumber: Number = 0, colStart: Number = <firstTextColumn>): Array
export function find(directory: String, names: String | Array<string>): ?String
export function findCached(directory: String, names: String | Array<string>): ?String
export function findAsync(directory: String, names: String | Array<string>): Promise<?String>
export function findCachedAsync(directory: String, names: String | Array<string>): Promise<?String>
export function tempFile<T>(fileName: String, fileContents: String, callback: Function<T>): Promise<T>
export function tempFiles<T>(filesNames: Array<{ name: String, contents: String }>, callback: Function<T>): Promise<T>

Unique Spawning

To make sure that old processes spawned by your linter provider are terminated on a newer invocation, you can specify uniqueKey: "my-linter" in exec or execNode options. Please note that killed processes will return null as return value, so make sure to handle that.

Example:

import atomLinter from 'atom-linter'

const myLinter = {
  // ...
  async lint(textEditor) {
    const output = atomLinter.exec('myprogram', ['parameter1', 'parameter2'], { uniqueKey: 'my-linter' })
    // NOTE: Providers should also return null if they get null from exec
    // Returning null from provider will tell base linter to keep existing messages
    if (output === null) {
      return null
    }
    // ... parse output and return messages
    return []
  }
}

License

This project is licensed under the terms of MIT License, see the LICENSE file for more info

changelog

Changelog

10.0.0

  • Add uniqueKey support to exec options
  • exec: Breaking: Rename throwOnStdErr to `throwOnStderr
  • exec: Support Buffers in options.stdin
  • exec: Kill all subprocesses properly on windows

9.0.1

  • Make exec and execNode behave the way they were supposed and documented to be by restoring their 10 seconds default timeout

9.0.0

  • Rename rangeFromLineNumber to generateRange
  • Return Range-compatible Array instead of Range in generateRange
  • Show line number in col too big error messages
  • Handle ENOENT properly and show a nice message
  • Bump sb-exec to v3.0.3 to include fix for an inconsistent behavior on windows bug (See steelbrain/exec#48)
  • Bump sb-exec to 3.1.0 to include kill() support for spawned processes

8.0.0

  • Upgrade from `sb-exec@2.xtosb-exec@3.x` to include compatibility fixes for npm path and general fixes for Windows

7.0.0

  • Return Ranges from rangeFromLineNumber
  • Make rangeFromLineNumber return entire line if no colStart is provided. (API breaking change)

6.0.0

  • Update rangeFromLineNumber to return a range that wraps a word not an entire line. (API breaking change)

5.0.2

  • Bump patch version of sb-exec to include support for non-stringish parameters

5.0.1

  • Bump patch version of sb-exec to include ignoreExitCode option

5.0.0

  • Bump major version of sb-exec, it contains fixes for windows and improved handling of error codes. This change shouldn't break most of the dependents, but if it does, they can be fixed by setting allowEmptyStderr to true in exec* methods

4.7.1

  • Use an alternative technique to export exec and execNode methods to allow temporary assignments, such as in-specs to work

4.7.0

  • Use sb-exec for process execution, to include a bugfix for Atom 1.7.0

4.6.1

  • Republish because of an unknown deployment issue

4.6.0

  • Add timeout option to exec, with a default value of 10 seconds
  • Use consistent-env instead of consistent-path

4.5.1

  • Fix for runtimes which don't have the atom module

4.5.0

  • Internal cleanup

  • Fix a bug with findCachedAsync where it would throw error if requested file wasn't found (#105)

  • Fix a bug where text editors won't be validated properly for Atom versions < 1.4.0

  • Trim outputs of exec commands

4.4.0

  • Highlight the whole first line when no line is given

4.3.4

  • Do not add g flag to regex if it already exists

4.3.3

  • Switch to named-js-regexp instead of xregexp for parse method

4.3.2

  • Fix a bug where linter execution modifies process.env

4.3.1

  • Remove createElement helper, reason is nobody was using it (according to GitHub code search)

  • Upgrade consistent-path version to include fix for critical typo

4.3.0

  • Add tempFiles helper

4.2.0

  • Use consistent-path package to determine $PATH correctly on OSX

4.1.1

  • Export FindCache, now you can do Helper.FindCache.clear() to clear find cache

4.1.0

  • Add findCachedAsync helper
  • Add findCached helper

4.0.1

  • Upgrade dependencies

4.0.0

  • Use ES6 exports instead of commonjs

  • Remove Helpers.findFile$ in favor of Helpers.find$

  • Use XRegExp.forEach instead of splitting given input by lines and applying regex over each line (mostly backward compatible, but no guarantee)

3.4.1

  • Revert ES6 exports to use commonjs again (broke compatibility with babel packages)

  • Rename Helpers.findFile$ to Helpers.find$ (also exported with previous names for backward compatibility)

  • Fix a non-critical bug in Helpers.find$ where it won't search in drive root

3.4.0

  • Add Helpers.findFileAsync
  • Add dist files for inclusion in non-babel envs

3.3.9

  • Revert the changes in 3.3.2, Range()'s end point is exclusive, not inclusive.

3.3.8

  • Fix rangeFromLineNumber on files with mixed indentation

3.3.7

  • Force lineNumber in rangeFromLineNumber to be within buffer range

3.3.6

  • Handle column start in rangeFromLineNumber, when it is greater than line length

  • Handle negative column start values and invalid line numbers

3.3.5

  • Add Helpers.createElement

3.3.4

  • Handle invalid lineNumber and return a valid range

3.3.3

  • Fix an API deprecation with TextEditor

3.3.2

  • Fix a bug in Helpers.rangeFromLineNumber

3.3.1

  • Future proof a check

3.3.0

  • Add flags option to parse method

3.2.2

  • Show a nicer message for EACCES errors

3.2.1

  • Couple of fixes for findFile
  • Correct npm test script

3.2.0

  • Add support for third-argument to rangeFromLineNumber

3.1.4

  • Fixed an undefined variable reference

3.1.3

  • Added tempFile method

3.1.2

  • Added support for both streams

3.1.1

  • Pass the options on to BufferedProcess

3.1.0

  • Add rangeFromLineNumber(textEditor, lineNumber)

3.0.1

  • Reject with an Error, instead of a string if stderr encountered unexpectedly

3.0.0

  • Throw an error if something is seen on stderr when throwOnStdErr is true

2.0.5

  • Add options.throwOnStdErr to the exec() options, defaulting to false

2.0.4

  • Remove OS key properly on all platforms

2.0.3

  • Remove OS key from the environment

2.0.2

  • Use Atom's BufferedProcess instead of child_process
  • Throw an error if output is seen on stderr, unless stream is stderr

2.0.1

  • Copy Atom's environment to the spawned process

2.0.0

  • execFilePath() replaced by execNode()

1.0.3

  • Verify the data passed to parse() is a string

1.0.2

  • Add findFile(startDir, names)

1.0.1

  • Initial release