Ejemplo n.º 1
0
        static int CheckFile(string filename, CommandLineOptions options, FileType fileType)
        {
            var fileContents = File.ReadAllLines(filename);

            // Look for common source code formatting errors (note: FileType.Cpp covers all C-family syntaxes, including C#).
            if (options.CheckFormatting && fileType == FileType.Cpp)
            {
                CheckFormatting(filename, fileContents, options);
            }

            if (Enumerable.SequenceEqual(options.CopyrightBanner[fileType], fileContents.Take(options.CopyrightBanner[fileType].Length)))
            {
                // This file already has the correct copyright.
                return(0);
            }
            else
            {
                if (options.Validate)
                {
                    // Just report that the copyright does not match.
                    Console.WriteLine("Error: Wrong copyright: {0}", options.GetRelativeName(filename));
                }
                else
                {
                    // Find any existing copyright.
                    var existingCopyright = fileType.GetExistingCopyrightBanner(fileContents);

                    if (options.PreviousCopyrightBanner != null && !Enumerable.SequenceEqual(existingCopyright, options.PreviousCopyrightBanner[fileType]))
                    {
                        // Warn if what we tried to overwrite doesn't match the expected previous (then don't actually edit anything).
                        Console.WriteLine("Warning: Skipping {0}: doesn't match previous copyright", options.GetRelativeName(filename));
                    }
                    else
                    {
                        // Remove the old copyright.
                        var withoutOldCopyright = fileContents.Skip(existingCopyright.Count());

                        // Insert the new copyright.
                        var withNewCopyright = options.CopyrightBanner[fileType].Concat(withoutOldCopyright);

                        // Write out the new file.
                        Console.WriteLine("Warning: Updating copyright: {0}", options.GetRelativeName(filename));

                        File.WriteAllLines(filename, withNewCopyright);
                    }
                }

                return(1);
            }
        }
Ejemplo n.º 2
0
 static void OutputFormatWarnings(string filename, IEnumerable <int> linesWithWarnings, CommandLineOptions options, string message)
 {
     foreach (var lineNumber in linesWithWarnings)
     {
         Console.WriteLine("{0}({1}): Warning: {2}", options.GetRelativeName(filename), lineNumber + 1, message);
     }
 }
Ejemplo n.º 3
0
        static int CheckFile(string filename, CommandLineOptions options, FileType fileType)
        {
            var fileContents = File.ReadAllLines(filename);

            // Look for common source code formatting errors (note: FileType.Cpp covers all C-family syntaxes, including C#).
            if (options.CheckFormatting && fileType == FileType.Cpp)
            {
                CheckFormatting(filename, fileContents, options);
            }

            if (Enumerable.SequenceEqual(options.CopyrightBanner[fileType], fileContents.Take(options.CopyrightBanner[fileType].Length)))
            {
                // This file already has the correct copyright.
                return 0;
            }
            else
            {
                if (options.Validate)
                {
                    // Just report that the copyright does not match.
                    Console.WriteLine("Error: Wrong copyright: {0}", options.GetRelativeName(filename));
                }
                else
                {
                    // Find any existing copyright.
                    var existingCopyright = fileType.GetExistingCopyrightBanner(fileContents);

                    if (options.PreviousCopyrightBanner != null && !Enumerable.SequenceEqual(existingCopyright, options.PreviousCopyrightBanner[fileType]))
                    {
                        // Warn if what we tried to overwrite doesn't match the expected previous (then don't actually edit anything).
                        Console.WriteLine("Warning: Skipping {0}: doesn't match previous copyright", options.GetRelativeName(filename));
                    }
                    else
                    {
                        // Remove the old copyright.
                        var withoutOldCopyright = fileContents.Skip(existingCopyright.Count());

                        // Insert the new copyright.
                        var withNewCopyright = options.CopyrightBanner[fileType].Concat(withoutOldCopyright);

                        // Write out the new file.
                        Console.WriteLine("Warning: Updating copyright: {0}", options.GetRelativeName(filename));

                        File.WriteAllLines(filename, withNewCopyright);
                    }
                }

                return 1;
            }
        }
Ejemplo n.º 4
0
 static void OutputFormatWarnings(string filename, IEnumerable<int> linesWithWarnings, CommandLineOptions options, string message)
 {
     foreach (var lineNumber in linesWithWarnings)
     {
         Console.WriteLine("{0}({1}): Warning: {2}", options.GetRelativeName(filename), lineNumber + 1, message);
     }
 }