soullivaneuh / styleci-fixers

[DEPRECATED] Replaced by a new project =>
https://flintci.io
4 stars 3 forks source link

Added wrapper definition for php-cs-fixer 2 #14

Closed core23 closed 7 years ago

core23 commented 7 years ago

Added the defintion based on https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/UPGRADE.md

GrahamCampbell commented 7 years ago

This list is incorrect I'm afraid, also implementation has some real subtleties, like, some fixers need parts turning off. Like I said, StyleCI's virtual fixer maps are quite large, and there are two mapps needed, due to the initial fixer bootstrapping needed to null them, as it were, and even then, the process of enabling the same fixer from two virtual ones takes a bit of care.

Low down: this package should use the API that I've added.

GrahamCampbell commented 7 years ago

Pass a StyleCI config file as the "config" arg to https://api.styleci.io/rules.

sstok commented 7 years ago

@GrahamCampbell the API still has a few bugs 🙂

preset: symfony

linting: true

enabled:
    - newline_after_open_tag
    #- ordered_class_elements
    - ordered_use
    - phpdoc_order
    - short_array_syntax
    - unalign_equals
    - unalign_double_arrow

    # Strict
    - strict_param
    - declare_strict_types

disabled:
    - phpdoc_no_empty_return
    - simplified_null_return
    - no_useless_return

finder:
    path:
        - 'src/'
        - 'tests/'
    not-path:
        - 'spec/'
        - 'Fixtures'
        - 'doc'

Gives

array (
  'array_syntax' => 
  array (
    'syntax' => 'short',
  ),
  'binary_operator_spaces' => 
  array (
    'align_equals' => false,
    'align_double_arrow' => true,
  ),
  'blank_line_after_namespace' => true,
  'blank_line_after_opening_tag' => true,
  'blank_line_before_return' => true,
  'braces' => true,
  'cast_spaces' => true,
  'class_definition' => true,
  'concat_space' => 
  array (
    'spacing' => 'none',
  ),
  'declare_equal_normalize' => true,
  'elseif' => true,
  'encoding' => true,
  'full_opening_tag' => true,
  'function_declaration' => true,
  'function_typehint_space' => true,
  'general_phpdoc_annotation_remove' => 
  array (
    0 => 'access',
    1 => 'package',
    2 => 'subpackage',
  ),
  'hash_to_slash_comment' => true,
  'heredoc_to_nowdoc' => true,
  'include' => true,
  'indentation_type' => true,
  'line_ending' => true,
  'lowercase_cast' => true,
  'lowercase_constants' => true,
  'lowercase_keywords' => true,
  'method_argument_space' => true,
  'method_separation' => true,
  'native_function_casing' => true,
  'new_with_braces' => true,
  'no_alias_functions' => true,
  'no_blank_lines_after_class_opening' => true,
  'no_blank_lines_after_phpdoc' => true,
  'no_closing_tag' => true,
  'no_empty_phpdoc' => true,
  'no_empty_statement' => true,
  'no_extra_consecutive_blank_lines' => 
  array (
    0 => 'throw',
    1 => 'use',
    2 => 'useTrait',
    3 => 'extra',
  ),
  'no_leading_import_slash' => true,
  'no_leading_namespace_whitespace' => true,
  'no_mixed_echo_print' => 
  array (
    'use' => 'echo',
  ),
  'no_multiline_whitespace_around_double_arrow' => true,
  'no_multiline_whitespace_before_semicolons' => true,
  'no_short_bool_cast' => true,
  'no_singleline_whitespace_before_semicolons' => true,
  'no_spaces_after_function_name' => true,
  'no_spaces_around_offset' => 
  array (
    0 => 'inside',
    1 => 'outside',
  ),
  'no_spaces_inside_parenthesis' => true,
  'no_trailing_comma_in_list_call' => true,
  'no_trailing_comma_in_singleline_array' => true,
  'no_trailing_whitespace' => true,
  'no_trailing_whitespace_in_comment' => true,
  'no_unneeded_control_parentheses' => true,
  'no_unreachable_default_argument_value' => true,
  'no_unused_imports' => true,
  'no_useless_return' => true,
  'no_whitespace_before_comma_in_array' => true,
  'no_whitespace_in_blank_line' => true,
  'normalize_index_brace' => true,
  'object_operator_without_whitespace' => true,
  'ordered_imports' => 
  array (
    'sortAlgorithm' => 'alpha',
  ),
  'phpdoc_align' => true,
  'phpdoc_indent' => true,
  'phpdoc_inline_tag' => true,
  'phpdoc_no_alias_tag' => 
  array (
    'type' => 'var',
  ),
  'phpdoc_order' => true,
  'phpdoc_scalar' => true,
  'phpdoc_separation' => true,
  'phpdoc_single_line_var_spacing' => true,
  'phpdoc_summary' => true,
  'phpdoc_to_comment' => true,
  'phpdoc_trim' => true,
  'phpdoc_types' => true,
  'phpdoc_var_without_name' => true,
  'psr4' => true,
  'self_accessor' => true,
  'short_scalar_cast' => true,
  'simplified_null_return' => true,
  'single_blank_line_at_eof' => true,
  'single_blank_line_before_namespace' => true,
  'single_class_element_per_statement' => true,
  'single_import_per_statement' => true,
  'single_line_after_imports' => true,
  'single_quote' => true,
  'space_after_semicolon' => true,
  'standardize_not_equals' => true,
  'switch_case_semicolon_to_colon' => true,
  'switch_case_space' => true,
  'ternary_operator_spaces' => true,
  'trailing_comma_in_multiline_array' => true,
  'trim_array_spaces' => true,
  'unary_operator_spaces' => true,
  'visibility_required' => 
  array (
    0 => 'method',
    1 => 'property',
  ),
  'whitespace_after_comma_in_array' => true,
)
  array (
    'align_equals' => false,
    'align_double_arrow' => true,
  ),

Why is the align_double_arrow enabled??

ordered_imports is not configurable no_useless_return is enabled? But I explicitly disabled this.

GrahamCampbell commented 7 years ago

@GrahamCampbell the API still has a few bugs 🙂

Actually, that won't be a bug in the API as such. The API is correct in that it exactly matches what StyleCI is doing... The bug is that StyleCI is actually configuring things like that. That's quite a shock! Thanks for reporting!

GrahamCampbell commented 7 years ago

I'm really confused now. Our tests give:

image

GrahamCampbell commented 7 years ago

Oh, haha. You must be setting the wrong variable with the config there. StyleCI is giving you the rules for the empty config file.

sstok commented 7 years ago

It seems you are correct.

635412533686232669

I'm using the following URL.

https://api.styleci.io/rules?conf={ preset: symfony, linting: true, enabled: [newline_after_open_tag, ordered_use, phpdoc_order, short_array_syntax, unalign_equals, unalign_double_arrow, strict_param, declare_strict_types], disabled: [phpdoc_no_empty_return, simplified_null_return, no_useless_return], finder: { path: [src/, tests/], not-path: [spec/, Fixtures, doc] } }

Edit. https://api.styleci.io/rules?conf=preset: symfony, linting: true, enabled: [newline_after_open_tag, ordered_use, phpdoc_order, short_array_syntax, unalign_equals, unalign_double_arrow, strict_param, declare_strict_types], disabled: [phpdoc_no_empty_return, simplified_null_return, no_useless_return], finder: { path: [src/, tests/], not-path: [spec/, Fixtures, doc] } seems to work.

EDIT2. NO OFF COURSE THAT DID NOT WORK! 🙌 not even running it through urlencode makes it work 😩

This is the script I'm using (from vendor/bin)

<?php

require '../autoload.php';

use Symfony\Component\Yaml\Yaml;

$yaml = Yaml::dump(Yaml::parse(file_get_contents(__DIR__.'/../../.styleci.yml')), 0, 2, Yaml::DUMP_OBJECT);
$url = 'https://api.styleci.io/rules?conf='.urlencode(substr($yaml, 2, -2));

$output = var_export(json_decode(file_get_contents($url), true), true);

echo $url."\n";
echo $output;

// echo str_replace(['array(', 'array (', ')'], ['[', '[', ']'], preg_replace(['/\d+ => /', "/'[^']+' => false,\\s+/i"], '', $output));
sstok commented 7 years ago

config !== config I'm going to kill my self now 💀

GrahamCampbell commented 7 years ago

You can also pass it as a json body in the request and that should work. (i've not actually tried tho)

GrahamCampbell commented 7 years ago

Maybe I should have made this endpoint, POST, lol.

sstok commented 7 years ago

It seems to be working now 😵

<?php

require '../autoload.php';

use Symfony\Component\Yaml\Yaml;

$yaml = Yaml::parse(file_get_contents(__DIR__.'/../../.styleci.yml'));
$url = 'https://api.styleci.io/rules?config='.json_encode($yaml);
$output = var_export(json_decode(file_get_contents($url), true), true);

echo str_replace(['array(', 'array (', ')'], ['[', '[', ']'], $output);
GrahamCampbell commented 7 years ago

str_replace(['array(', 'array (', ')'], ['[', '[', ']'], $output);

hax

GrahamCampbell commented 7 years ago

$url = 'https://api.styleci.io/rules?config='.json_encode($yaml);

Wait, wut. I swear that's meant to be yaml, not json?

GrahamCampbell commented 7 years ago

image

Which, 3 steps down, calls:

image

GrahamCampbell commented 7 years ago

You can also pass it as a json body in the request and that should work. (i've not actually tried tho)

I really did strictly mean that. As in a json body {"config": "yaml config goes here"} as the "body". The config MUST be yaml.

sstok commented 7 years ago

The outputted JSON is parsable as YAML 😳 but only because Symfony atm accepts "preset":"symfony" which is not actually valid.

Guess I should use https://github.com/StyleCI/SDK/blob/master/src/Client.php 😅 Which doesn't have the /rules endpoint yet 🙈

Anyway I will wait till the bridge package is updated, I just needed to get php-cs-fixer working again.

GrahamCampbell commented 7 years ago

Which doesn't have the /rules endpoint yet 🙈

LOL. I forgot that package even existed.

soullivaneuh commented 7 years ago

@core23 The Fixers.php file is an auto-generated file.

Could you please instead implement this property onto Fixers.php.twig and FixersGenerator.php?

Thanks and sorry for the answer delay.

soullivaneuh commented 7 years ago

Low down: this package should use the API that I've added.

@GrahamCampbell It is! :smile:

core23 commented 7 years ago

Will have a look at this the next days

GrahamCampbell commented 7 years ago

@Soullivaneuh No, it doesn't I've not even added this endpoint to the SDK. :P

soullivaneuh commented 7 years ago

@Soullivaneuh No, it doesn't I've not even added this endpoint to the SDK. :P

Ha ha! :smile:

Is it planned to be?

GrahamCampbell commented 7 years ago

yeh, when i get the time :)

soullivaneuh commented 7 years ago

@GrahamCampbell Great. :+1:

Just to be sure, because php-cs-fixer 2.x config is now really different than StyleCI one, (e.g. long_array_syntax and short_array_syntax becoming array_syntax with options), what is your plan for the future?

Proposes a /rules or /alias-options like @core23 did manually from the API? This will keep the configuration different but will be style be compatible with the bridge updated.

Change your configuration definition to have the same structure as php-cs-fixer 2.x? Something like:

rules:
  array_syntax:
    syntax: short

It would be the best IMHO but I remember you was not really happy about this.

soullivaneuh commented 7 years ago

BTW, if I can help on anything about this, please tell me! :wink:

GrahamCampbell commented 7 years ago

The config structure is not changing. This means the mapping is very complex.

soullivaneuh commented 7 years ago

The config structure is not changing. This means the mapping is very complex.

Well, I'll work on it once your API will give us enough information for that! :wink:

core23 commented 7 years ago

Don't get this started, sorry

sstok commented 7 years ago

FYI, you can "extract" the fixer aliases by using the preset "none" and then only enabling each alias, you will bombard the API then, but it is possible to extract the information behind.

As a more "friendly" alternative you can use the API to fetch the actual configuration and store this eg:

Whenever StyleCI's rules change you will still need to remove the cache, but at least that is allot less work then copying the rules 🙂

22/01/2016 - Symfony Tweak

The simplified_null_return fixer has been removed from the symfony preset.

I know England has it's own timezone but this is ridiculous 😂 , accept it 2017 is here 🙈

core23 commented 7 years ago

Can you help with this PR @sstok ?

sstok commented 7 years ago

@core23 Sorry for the late reply, I have to many things on me plate atm so I can't help 😞