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

Expand configuration options #115

Merged
merged 6 commits into from
Sep 19, 2017
Merged

Expand configuration options #115

merged 6 commits into from
Sep 19, 2017

Conversation

mdeboer
Copy link
Contributor

@mdeboer mdeboer commented Sep 12, 2017

As I was getting sick and tired of constantly getting the error message that PHPMD could not be executed in my projects because of a missing phpmd.xml, I decided to make the changes that have already been made to linter-phpcs 😄

  • Added more configuration options (much like linter-phpcs)
  • Added .editorconfig
  • Updated outdated contributing guidelines
  • Added more tests

Fixes #102.
Fixes #106.

@mdeboer
Copy link
Contributor Author

mdeboer commented Sep 12, 2017

I suggest this to be released as v1.6.0 as configuration options aren't backwards compatible.

Once this PR is merged I can make another PR for #24 and add the option to configure when to lint,
on change or on-the-fly 😄 Maybe, just maybe do the same for linter-phpcs?

Copy link
Member

@Arcanemagus Arcanemagus left a comment

Choose a reason for hiding this comment

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

Here's what I see just looking over the code.

.editorconfig Outdated
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
Copy link
Member

Choose a reason for hiding this comment

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

🐛 Apparently you didn't have this file there when editing it, as this is missing the trailing newline 😉.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did, but as you can see, it doesn't include an entry for a .editorconfig 😉

lib/main.js Outdated

this.subscriptions = new CompositeDisposable();

// FIXME: Remove after a few versions
Copy link
Member

Choose a reason for hiding this comment

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

🔥 This setting never existed here, as such we don't need to include code removing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took this from linter-phpcs, don't look at me 😉

}

loadDeps();
const fileDir = path.dirname(filePath);
Copy link
Member

Choose a reason for hiding this comment

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

You'll need a check that filePath isn't null, although it should be impossible, sometimes linter will call Providers with TextEditors that don't have this defined (usually on restoring a session on restarting Atom).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, this needs to be fixed in linter-phpcs as well then, as far as I can remember.

Copy link
Member

Choose a reason for hiding this comment

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

Yea, many of the providers still need the guard added to them, for some reason it's rarely an issue for most providers (I think it's a race condition in the TextEditor initializing and maybe they are slow enough it's not an issue? 😕).

@@ -0,0 +1,1620 @@
{
Copy link
Member

@Arcanemagus Arcanemagus Sep 12, 2017

Choose a reason for hiding this comment

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

🔥 Until Greenkeeper figures out updating of this automatically in their main integration I'm holding off on adding this to more repositories as currently it is a very manual process that gets forgotten. The version of npm in apm doesn't even utilize this anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah okay, I'll remove it 👍

lib/main.js Outdated
scope: 'file',
lintOnFly: false,
lintsOnChange: true,
Copy link
Member

Choose a reason for hiding this comment

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

🔥🐛 This is still a v1 provider, so this needs to stay lintOnFly. Also, as we aren't passing in the file contents this needs to stay false!

lib/main.js Outdated
this.subscriptions.dispose();
},

provideLinter() {
return {
name: 'PHPMD',
grammarScopes: ['text.html.php', 'source.php'],
grammarScopes,
Copy link
Member

Choose a reason for hiding this comment

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

🔥 Since there is no need to change the scopes, let's just keep these as statically declared here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Took this straight from linter-phpcs, I'm not familiar with these kind of packages and the comment made sense.

lib/main.js Outdated
}
}

// Check if a rulesets file exists and handle it
const confFileNames = ['phpmd.xml', 'phpmd.xml.dist', 'phpmd.ruleset.xml'];
const confFile = await helpers.findAsync(fileDir, confFileNames);
Copy link
Member

Choose a reason for hiding this comment

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

🐎 Put this behind a check on this.autoConfigSearch, there's no point in spending the I/O time searching for these files if we aren't going to use them!

The rulesets declaration down on 114 could probably be moved partially into here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense 👍

lib/main.js Outdated
};

const output = await helpers.exec(executablePath, parameters, options);
if (confFile) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this up underneath the projectPath logic, and do similar logic there. That way all the cwd modifying logic is in one place. It might make sense to have both set a cwd variable instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, I'll have a look!

lib/main.js Outdated
}
}

// Local variables
Copy link
Member

Choose a reason for hiding this comment

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

🔥 this, see below for reasoning.

@@ -0,0 +1,7 @@
root = true
Copy link
Member

Choose a reason for hiding this comment

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

Can you change this to the version used elsewhere? (this).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure no problem 👍

@Arcanemagus
Copy link
Member

Breaking changes in the configuration would need a major release btw.

@mdeboer
Copy link
Contributor Author

mdeboer commented Sep 13, 2017

I'll get on with the changes @Arcanemagus, thank you for your feedback and I'll update this PR tomorrow 👍

@mdeboer
Copy link
Contributor Author

mdeboer commented Sep 16, 2017

It took me a little longer, things came up but I think I fixed it all without breaking anything 😉

Copy link
Member

@Arcanemagus Arcanemagus left a comment

Choose a reason for hiding this comment

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

Almost there!

insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
Copy link
Member

Choose a reason for hiding this comment

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

Still missing the ending newline 😛.

Note, you can change the whitespace package's options to handle this for you automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fial. Fail.

lib/main.js Outdated
const rulesetPath = await helpers.findAsync(filePath, rulesets);
if (rulesetPath !== null) {
ruleset = rulesetPath;
if (fileText === '' || filePath === null) {
Copy link
Member

Choose a reason for hiding this comment

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

It can also be undefined, this is one of the cases where it should just be if (fileText === '' || !filePath).

lib/main.js Outdated
}),
atom.config.observe('linter-phpmd.rulesets', (value) => {
Copy link
Member

Choose a reason for hiding this comment

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

Remember how I said to remove that check on the executableTimeout from phpcs? We actually need the same code, but for this setting, sorry!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, working on multiple projects so I'll have to dig into that to see what you mean 😜

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, to make it backwards compatbile! 👍

package.json Outdated
"default": -1,
"minimum": -1,
"description": "Rule priority threshold; rules with lower priority than this will not be used.",
"order": 7
Copy link
Member

Choose a reason for hiding this comment

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

🐛 5 -> 7?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, I must have removed an option and not updated the order.

@mdeboer
Copy link
Contributor Author

mdeboer commented Sep 18, 2017

Okay done! 👍

lib/main.js Outdated

// Backwards compatibility
if (atom.config.get('linter-phpmd.rulesets') !== undefined) {
this.rulesOrConfigFile = atom.config.get('linter-phpmd.rulesets');
Copy link
Member

Choose a reason for hiding this comment

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

atom.config.set('linter-phpmd.rulesOrConfigFile', atom.config.get('linter-phpmd.rulesets'));

We want to save their old setting, not grab it this one time and then lose it forever 😉.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doh, you're right 🙄 where's my head at? 😜

@mdeboer
Copy link
Contributor Author

mdeboer commented Sep 18, 2017

There you go, that should be it. Lesson learnt on linters, thanks! Possibly hate writing them more than using them 😜

Copy link
Member

@Arcanemagus Arcanemagus left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for working through this!

@Arcanemagus Arcanemagus changed the title Update configuration options Expand configuration options Sep 19, 2017
@Arcanemagus Arcanemagus merged commit 7fc108f into AtomLinter:master Sep 19, 2017
@Arcanemagus
Copy link
Member

Published as v2.0.0, thanks again!

@mdeboer
Copy link
Contributor Author

mdeboer commented Sep 19, 2017

Awesome, you're very welcome! Thanks again for your directions 👍 Next on the list is probably being able to lint on-the-fly but we'll see, first have to get back to work 😆

@Arcanemagus
Copy link
Member

I'm not sure I'm a fan personally of the way to get linters like this to lint on the fly. The only way that has been figured out so far is to create a temporary file from the current contents, and then lint that. This only works on simple linters that have no dependency on the state of the rest of the project, and causes a lot of I/O.

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.

2 participants