Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Update: Use latest linter API #55

Merged
merged 1 commit into from
Aug 17, 2015

Conversation

SpainTrain
Copy link
Member

  • Use latest atom linter API
  • Use helpers from atom-linter
  • Refactor to use latest linter plugin conventions (main.coffee, etc.)

Testing

This is a significant change, so it would be great if folks could test it out to ensure it works with their environment/config.

  1. Checkout this PR (instructions)
  2. cd into your linter-pylint directory
  3. Install into your dev packages - apm link --dev
  4. Run atom in dev mode - atom -d

Using these directions will not affect your current linter-pylint. You can go back to normal by running atom without the -d flag.

If you do run into issues, please comment and provide:

  • OS and version
  • atom version
  • linter version
  • Reasonably detailed description of the problem

Closes #52 #53 #51 #50 #49


This change is Reviewable

@SpainTrain
Copy link
Member Author

onTheFly isn't working. I need to lint the text from the buffer not the file. Will fix.

@steelbrain steelbrain self-assigned this Aug 14, 2015
executable:
type: 'string'
default: 'pylint'
rcFile:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't pylint automatically search for rc file in the file tree?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be useful to be able to use a rc file that lives in a different location

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, then I am neutral on the idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was part of keeping feature and behavior parity with the current version. In general it seems ok to expose often used cli flags via the config. I'm also neutral though 😁

@steelbrain
Copy link
Contributor

waiting for a few reports of confirming this works, I might test this as well, but not in a position to do so any time soon.
/cc @peduxe @Arcanemagus

@SpainTrain SpainTrain force-pushed the update-to-latest-api branch from c3d7c95 to 71c2364 Compare August 14, 2015 21:11
@SpainTrain
Copy link
Member Author

@steelbrain I have fixed the onTheFly issue and made a couple other changes to this PR:

  • Suppress info message type
  • Allow PYTHONPATH config (useful if you are vendoring your deps)
  • Do not suppress error messages if pylint print anything to stderr
  • Set cwd of spawned pylint process to current project directory
  • Add current project dir to PYTHONPATH (this fixes import issue described here Linting on temporary files means imports don't work #23)

projDir = @getProjDir(file)
cwd = projDir
pythonPath = @pythonPath.replace(/%p/g, projDir)
env = _.merge {}, process.env,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about you do Object.create(process.env) here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args.push "--rcfile=#{@rcFile}"
args.push tmpFilename
return helpers.exec(@executable, args, {env: env, cwd: cwd}).then (output) =>
_.reject helpers.parse(output, @regex, {filePath: file}), {type: 'info'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why would you need _.reject here. You can completely drop lodash IMO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a convenient way to suppress messages of type info. Admittedly, I could instead use filter and a whitelist approach.

Concerning lodash, I am also using trim, compact, and find, which I think provides some value and conciseness for our code.

Happy to remove it if it's an issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not an issue 😃 But I am against importing modules that could easily be replaced by native code. Also we have a String.prototype.trim in native JS.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reasonable.

RE: trim, unfortunately native trim only trims whitespace. I needed to trim : from use input, since I add the : later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_.reject does the same thing as helpers.parse(...).filter(e => e) right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but with sugar - you can give it an object rather than a function. It removes any items with properties that match. IMO it is pretty fluent since you can basically read it as "reject from array if type is 'info'". Native filter alternative is

helpers.parse(output, @regex, {filePath: file}).filter (lintIssue) -> lintIssue.type isnt 'info'

which is also pretty concise and fluent 😁

@SpainTrain
Copy link
Member Author

All comments should be addressed

@steelbrain
Copy link
Contributor

@Arcanemagus would you have some time to try this one?

@Arcanemagus
Copy link
Member

Looks like it can't handle ignoring the error message at the start about no config file being found.
image

Atom is not being helpful with where it's allowing me to set breakpoints, still trying to verify that that's really what is breaking it.

@SpainTrain
Copy link
Member Author

Looks like it can't handle ignoring the error message at the start about no config file being found.

You are right about this. Originally I had ignored anything from stderr, but that seemed a bit annoying if someone is trying to get this plugin working in the face of real errors.

Let me see if I can find a way to suppress this specific warning.

@steelbrain
Copy link
Contributor

@Arcanemagus I am guessing that the program this linter uses writes something to stderr and we dislike something on stderr when we are expecting stdout, so we throw.

@steelbrain
Copy link
Contributor

@Arcanemagus
Copy link
Member

I do love how the example image on the pylint website has that error as well 😛. I've got this all setup now so I can test any future updates.

@SpainTrain
Copy link
Member Author

@SpainTrain We do have a throwOnStdErr option for exec. See https://github.com/AtomLinter/atom-linter/blob/master/spec/helper-spec.coffee#L45

Yup, that's what I was using before the temp file and other updates. The issue there is the user won't be notified of legitimate errors. For example, while I was doing some testing I had to go into the dev tools in atom just to see the legitimate errors that pylint was reporting.

It's possibly minor enough to just use throwOnStdErr: no for now and create a ticket to properly whitelist that particular error in the future, while reporting other legitimate errors.

@SpainTrain
Copy link
Member Author

I do love how the example image on the pylint website has that error as well .

That is amazing...

@SpainTrain
Copy link
Member Author

Actually, now I realize that I am setting PYTHONPATH incorrectly for windows, will fix

@SpainTrain SpainTrain force-pushed the update-to-latest-api branch from daaf85b to 290ea05 Compare August 17, 2015 20:46
@SpainTrain
Copy link
Member Author

✅ should play nice with Windows now!

@Arcanemagus
Copy link
Member

Checking out now.

@Arcanemagus
Copy link
Member

Looks like it's working at a basic level, haven't tested any of the settings but the main linter works.

@Arcanemagus
Copy link
Member

Btw, for errors that have 0 for their column you might want to use helpers.rangeFromLineNumber to generate a range that covers the entire text. As it currently stands you can't ever access the tooltip for those. (Meaning if there is trace data it is lost)

@SpainTrain SpainTrain force-pushed the update-to-latest-api branch from 290ea05 to 37bfc92 Compare August 17, 2015 21:01
@Arcanemagus
Copy link
Member

@steelbrain any issues that you can see preventing this getting merged?

@SpainTrain
Copy link
Member Author

Btw, for errors that have 0 for their column you might want to use helpers.rangeFromLineNumber to generate a range that covers the entire text.

About to push this change

@steelbrain
Copy link
Contributor

@Arcanemagus I am super-dooper busy, If this looks good to you, I am happy to merge.

* Use latest atom linter API
* Use helpers from atom-linter
* Refactor to use latest linter plugin conventions (main.coffee, etc.)

Closes AtomLinter#52 AtomLinter#53 AtomLinter#51 AtomLinter#50 AtomLinter#49
@SpainTrain SpainTrain force-pushed the update-to-latest-api branch from 37bfc92 to 4431f0b Compare August 17, 2015 21:36
@SpainTrain
Copy link
Member Author

Btw, for errors that have 0 for their column you might want to use helpers.rangeFromLineNumber to generate a range that covers the entire text.

Added this

.map (lintIssue) ->
[[lineStart, colStart], [lineEnd, colEnd]] = lintIssue.range
if lineStart == lineEnd and colStart <= colEnd <= 0
return _.merge {}, lintIssue,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.create would not work here

@steelbrain
Copy link
Contributor

@SpainTrain Thanks for all the hard work and effort You've put into this rewrite 👏

steelbrain added a commit that referenced this pull request Aug 17, 2015
@steelbrain steelbrain merged commit 4d653ca into AtomLinter:master Aug 17, 2015
@SpainTrain SpainTrain deleted the update-to-latest-api branch August 17, 2015 21:43
@SpainTrain
Copy link
Member Author

@SpainTrain Thanks for all the hard work and effort You've put into this rewrite

np, it's been fun, thx for merging

@SpainTrain
Copy link
Member Author

Oops, just realized I neglected to add the new config params to the README 😞

@steelbrain
Copy link
Contributor

Oops, just realized I neglected to add the new config params to the README

Another PR? 😃

@SpainTrain
Copy link
Member Author

Of course #56

@kevinji
Copy link

kevinji commented Aug 20, 2015

#49, #50, #51, and #53 still need to be closed; your commit message syntax only closed the first issue listed (you need "closes ___" for every issue).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants