Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default path mode to intersection #371

Closed
wants to merge 1 commit into from

Conversation

Landerstraeten
Copy link
Contributor

@Landerstraeten Landerstraeten commented Jun 16, 2017

Q A
Branch master
Bug fix? no
New feature? yes
BC breaks? yes
Deprecations? no
Documented? yes
Fixed tickets /

@veewee veewee added this to the Version 0.11.7 milestone Jun 16, 2017
@veewee
Copy link
Contributor

veewee commented Jun 16, 2017

Hi @Landerstraeten,

Thanks for your PR!

I've tested the PR and found out that during grumphp run no files were validated in php-cs-fixer2. I think that this is due that no files were added to the input, so the intersection is empty.
On the other hand, it does solve the issue of ignored files being validated during grumphp git:pre-commit.

I think it's best to fix this issue by removing the ability to configure the path modus and hardcode it:

  • During grumphp run: no path mode specified
  • During grumphp git:pre-commit: intersection path mode

In the last case, it's also an option to implement this issue:
#327

@keradus : Can you confirm that running intersection path mode with empty path arguments is causing an empty set to validate?

@keradus
Copy link
Contributor

keradus commented Jun 16, 2017

I can confirm. intersection is basically operation of sets. when one take common part of anything and empty set, it's always empty set

@keradus
Copy link
Contributor

keradus commented Jun 16, 2017

@veewee , hardcoded path mode would actually follow reasoning why we introduced intersection.
for regular run - always normal mode, for precommit/CI - always intersection

@keradus
Copy link
Contributor

keradus commented Jun 27, 2017

BC breaks? no

disagree, public argument was removed

@veewee
Copy link
Contributor

veewee commented Jun 28, 2017

It is indeed a BC break, I've changed the description and the milestone.
The code looks good at first sight. I'll do a more in-depth review this friday.

@@ -91,6 +86,8 @@ public function run(ContextInterface $context)
return $this->runOnAllFiles($context, $arguments);
}

$arguments->add('--path-mode=intersection');
Copy link
Contributor

Choose a reason for hiding this comment

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

it will crash with Cannot create intersection with not-fully defined Finder in configuration file. exception if there is no finder configured in .php_cs(.dist)? file.

Copy link
Contributor

Choose a reason for hiding this comment

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

How would you suggest to solve it?

Copy link
Contributor

Choose a reason for hiding this comment

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

you cannot know it without executing config file.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could execute the config file, but this won't be able if php-cs-fixer is ran in PHAR modus. In that case, the PhpCsFixer\Config won't be available.
I do understand why it crashes, but isn't it more logical if it runs in intersect modus without a finder, it runs on the specified files only? However, this would require a change in php-cs-fixer2.

Copy link
Contributor

@keradus keradus Jun 30, 2017

Choose a reason for hiding this comment

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

sorry, not sure what are modus

We could execute the config file, but this won't be able if php-cs-fixer is ran in PHAR modus.

not true. this is not related do you execute code under phar or not.

isn't it more logical if it runs in intersect modus without a finder

no, it intersect you need to have at least two collections. here, it's cli args + finder from config.

Copy link
Contributor

@keradus keradus Jul 2, 2017

Choose a reason for hiding this comment

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

As you mentioned, currently the best option is to handle errors with intersection and an empty finder.

and that means you need to load config from file and change it, it finder is not fully configured.
but that, again, would require grumphp to understand the code it's executing (know the classes etc), which, as other solutions I suggested, you refused.
you want to be aware of configuration but refuse to know it classes. not much you can do with that restriction (except run cli up to 2 times approach)

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @keradus ,

It's not that I refuse to know it classes, it's about some configurations using the globally installed php-cs-fixer. For locally installed fixers it wouldn't be a problem.
Instead of running the cli tool twice, it is also possible to make the path mode configurable again, but this time with a boolean that looks like intersect_on_commit with a default value of true. That would probably also fix this problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

you could know the classes and still execute phar from cli.

that new mode is a hacky way of doing this which abuse package that is external for you, putting special mode only for one user is no-go.
and that option is not intersect_on_commit, it's more like intersect_wich_finder_from_config_but_ignore_if_there_is_no_finder_in_config... hacky

Copy link
Contributor

Choose a reason for hiding this comment

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

@keradus,

The only way we could know these classes is by adding php-cs-fixer to the dependencies, even for projects who don't want to use that tool. So this is something I would like to avoid. Or are you talking about some other way?

To be sure we are talking about the same thing: I was talking about a configuration inside grumphp named intersect_on_commit which will use the intersect path mode during a commit inside GrumPHP. There is no need for any changes in php-cs-fixer for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was talking about a configuration inside grumphp named intersect_on_commit which will use the intersect path mode during a commit inside GrumPHP. There is no need for any changes in php-cs-fixer for that.

Cool it's gonna be internal setting.
yet, when intersect_on_commit would be set up, then you will end up with current issue as well, key is configured, intersection is tried to be used, yet no local config finder is provided.

Or are you talking about some other way?

if you don't want to have that as dependency and treat it as a blackbox, then:

poor, quick and dirty solution would be to execute command with intersection mode, if it crashes on not fully defined finder, run it with override mode...

@veewee
Copy link
Contributor

veewee commented Sep 1, 2017

Fixed in #395

@veewee veewee closed this Sep 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants