dotnet / codeformatter

Tool that uses Roslyn to automatically rewrite the source to follow our coding styles
MIT License
1.24k stars 244 forks source link

Renaming fields not working correctly #77

Open krwq opened 9 years ago

krwq commented 9 years ago

This happened for this piece of code:

        static readonly int Lzyyyy = "yyyy".Length;
        static readonly int Lzyyyy_ = "yyyy-".Length;
        static readonly int Lzyyyy_MM = "yyyy-MM".Length;
        static readonly int Lzyyyy_MM_ = "yyyy-MM-".Length;
        static readonly int Lzyyyy_MM_dd = "yyyy-MM-dd".Length;
        static readonly int Lzyyyy_MM_ddT = "yyyy-MM-ddT".Length;
        static readonly int LzHH = "HH".Length;
        static readonly int LzHH_ = "HH:".Length;
        static readonly int LzHH_mm = "HH:mm".Length;
        static readonly int LzHH_mm_ = "HH:mm:".Length;
        static readonly int LzHH_mm_ss = "HH:mm:ss".Length;
        static readonly int Lz_ = "-".Length;
        static readonly int Lz_zz = "-zz".Length;
        static readonly int Lz_zz_ = "-zz:".Length;
        static readonly int Lz_zz_zz = "-zz:zz".Length;
        static readonly int Lz__ = "--".Length;
        static readonly int Lz__mm = "--MM".Length;
        static readonly int Lz__mm_ = "--MM-".Length;
        static readonly int Lz__mm__ = "--MM--".Length;
        static readonly int Lz__mm_dd = "--MM-dd".Length;
        static readonly int Lz___ = "---".Length;
        static readonly int Lz___dd = "---dd".Length;

which got converted into:

        private static readonly int s_lzyyyy = "yyyy".Length;
        private static readonly int s_lzyyyy = "yyyy-".Length;
        private static readonly int s_lzyyyy_MM = "yyyy-MM".Length;
        private static readonly int s_lzyyyy_MM = "yyyy-MM-".Length;
        private static readonly int s_lzyyyy_MM_dd = "yyyy-MM-dd".Length;
        private static readonly int s_lzyyyy_MM_ddT = "yyyy-MM-ddT".Length;
        private static readonly int s_lzHH = "HH".Length;
        private static readonly int s_lzHH = "HH:".Length;
        private static readonly int s_lzHH_mm = "HH:mm".Length;
        private static readonly int s_lzHH_mm = "HH:mm:".Length;
        private static readonly int s_lzHH_mm_ss = "HH:mm:ss".Length;
        private static readonly int s_Lz = "-".Length;
        private static readonly int s_lz_zz = "-zz".Length;
        private static readonly int s_lz_zz = "-zz:".Length;
        private static readonly int s_lz_zz_zz = "-zz:zz".Length;
        private static readonly int s_Lz = "--".Length;
        private static readonly int s_lz__mm = "--MM".Length;
        private static readonly int s_lz__mm = "--MM-".Length;
        private static readonly int s_lz__mm = "--MM--".Length;
        private static readonly int s_lz__mm_dd = "--MM-dd".Length;
        private static readonly int s_Lz = "---".Length;
        private static readonly int s_lz___dd = "---dd".Length;

Once you get a closer look there are name collisions. In this particular change it makes sense to keep the names as they make sense.

jaredpar commented 9 years ago

I don't understand what the error is here.

khellang commented 9 years ago

@jaredpar Trailing underscores are removed :smile:

jaredpar commented 9 years ago

@khellang ah, thanks for pointing that out.

The logic for that part of the rule was to rename one of the other common private field name patterns:

private int field_;

I agree the behavior displayed here is bad, I'm just trying to find a way to rationalize the behavior so the intended case continues to get renamed but the above case does not. Maybe it's as simple as only removing trailing slashes when the field is camel cased.