Skip to content
Steel Brain edited this page Mar 25, 2016 · 49 revisions

The Linter API allows you to lint files of different specified scopes.

Note: Linter also supports PUSH style linters with a different API service. See Linter-Indie-API

Defining a provider

You will need to add this to your package.json file

"providedServices": {
  "linter": {
    "versions": {
      "1.0.0": "provideLinter"
    }
  }
}

Here's an example package returning a linter provider

Note: You can return more than one provider at once by wrapping them in an Array.

'use babel'
module.exports = {
  activate() {
    console.log('My package was activated')
  },
  deactivate() {
    console.log('My package was deactivated')
  },
  provideLinter() {
    const provider = {
      name: 'Some Linter',
      grammarScopes: ['source.js', 'source.php'], // ['*'] will get it triggered regardless of grammar
      scope: 'file', // or 'project'
      lintOnFly: false,
      lint: function(textEditor) {
        return new Promise(function(resolve, reject) {
          // do something async or
          return [{
            type: 'Error',
            text: 'Something went wrong',
            range:[[0,0], [0,1]],
            filePath: textEditor.getPath()
          }]
        })
      }
    }
    return provider
  }
}

If you think that you don't need to be asynchronous, then you can return the direct results instead of returning a Promise.

Messages

{
  type: string,
  text?: string,
  html?: string,
  name?: string,  // Only specify this if you want the name to be something other than your linterProvider.name
  filePath?: string,
  range?: Range,
  trace?: Array<Trace>,
  fix?: Fix,
  severity?: 'error' | 'warning' | 'info',
  selected?: Function
}

Note: You must either provide text or html, providing both is an error.

Trace

Trace objects can be used to provide traces or references to other files or positions. The type of traces can be anything, but is recommended to be 'Trace' for visual ease.

Screenshot

// Trace
{
  type: "Trace",
  text?: string,
  html?: string,
  name?: string,  // Only specify this if you want the name to be something other than your linterProvider.name
  filePath: string,
  range?: Range,
  class?: string,
  severity?: 'error' | 'warning' | 'info'
}
Fix

Fix objects allow a linter to suggest a possible fix to the user for a message's issue.

{
  range: Range,
  newText: string,
  oldText?: string
}

Note: Currently not implemented in Linter.

Clone this wiki locally