Help on linter standard-linter-v2 example


#1

I am a new both Atom and CoffeeScript as well as JavaScript. I try to get this simple example working, but maybe I am missing something obvious:

I generated the package with command:

apm init -p linter-example -javascript

Then I edited the package.json to look like this:

{
  "name": "linter-example",
  "main": "./lib/linter-example",
  "version": "0.0.0",
  "description": "A short description of your package",
  "keywords": [
  ],
  "activationCommands": {
    "atom-workspace": "linter-example:provideLinter"
  },
  "repository": "https://github.com/atom/linter-example",
  "license": "MIT",
  "engines": {
    "atom": ">=1.0.0 <2.0.0"
  },
  "dependencies": {
      "atom-linter": "^8.0.0",
      "atom-package-deps": "^4.0.1"
  },
  "providedServices": {
  "linter": {
    "versions": {
      "2.0.0": "provideLinter"
    }
  }
}
}

And copy pasted the example code to lib/linter-example.js

'use babel'

export function activate() {
  // Fill something here, optional
}

export function deactivate() {
  // Fill something here, optional
}

export function provideLinter() {
  return {
    name: 'Example',
    scope: 'file', // or 'project'
    lintsOnChange: true, // or true
    grammarScopes: ['source.js'],
    lint(textEditor) {
      const editorPath = textEditor.getPath()

      // Do something sync
      return [{
        severity: 'info',
        location: {
          file: editorPath,
          position: [[0, 0], [0, 1]],
        },
        excerpt: `A random value is ${Math.random()}`,
        description: `### What is this?\nThis is a randomly generated value`
      }]

      // Do something async
      return new Promise(function(resolve) {
        resolve([{
          severity: 'info',
          location: {
            file: editorPath,
            position: [[0, 0], [0, 1]],
          },
          excerpt: `A random value is ${Math.random()}`,
          description: `### What is this?\nThis is a randomly generated value`
        }])
      })
    }
  }
}

Then I ran Update Package Dependencies: Update

Then I have tried to update the atom by refreshing Ctrl+Shift+F5.

My end goal is to write linter-julia package by copying the idea from linter-pep8. I am pretty confident that I can manage the rest of the package development, but I couldn’t get this provideLinter function to get called.


#2

Looking at some other linters, I’m not seeing any use of ActivationCommands. ActivationHooks can be used to turn it on when a specific language is chosen as in linter-shellcheck, but linter-clang doesn’t use either property, which means that it activates (Atom loads all of its code) on startup.


#3

Thanks, but it didn’t help. I made the following changes (these might contains mistakes as well):

grammarScopes: ['source.c'],
"activationHooks": [
    "language-c:grammar-used"
],

The reasoning to change c-language: I don’t have another linter package installed for c-language, however this didn’t help.


#4

I uploaded the example package to github for easier debugging: https://github.com/TeroFrondelius/linter-example

Any help is appreciated.

cross reference: I also started issue in linter repo https://github.com/steelbrain/linter/issues/1299


#5

Replied on the github issue.

tldr; linter v2 is not yet published, you can use the v1 api for now. See the v1 github branch for it’s docs


#6

Thanks a real newbie mistake. However, this didn’t solve my whole problem. I updated the package according to the version one, but still it isn’t working. I believe I still have additional beginner mistake. If someone could look, it would be a really appreciated: https://github.com/TeroFrondelius/linter-example


#7

@steelbrain thanks a lot for the solution:


#8

If anyone is interested or for the future reference, I made the first version, not yet published though.