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

Added files option #52

Merged
merged 28 commits into from Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
06901ca
added files option resource
Mar 14, 2019
ac64e65
added files option
Mar 14, 2019
69e2f03
convert string from cli into an array of paths
Mar 14, 2019
2b1c4d2
pass list of files into formatter
Mar 14, 2019
1332047
added default value if files option isn't present
Mar 14, 2019
8ed11cf
need to check if files argument is null
Mar 14, 2019
2587cde
moved where file list is created
Mar 14, 2019
80bd14d
added null file list to existing tests
Mar 14, 2019
ebb3ad8
skip a document if the path is in the list
Mar 14, 2019
8f33cf4
added test for files option with a list of files
Mar 14, 2019
721fa70
fixed xlf files
Mar 14, 2019
1e0c7e5
added files option to readme
Mar 14, 2019
a7367e1
use unformatted project
Mar 20, 2019
74f932e
moved extra file into unformatted project
Mar 20, 2019
a4e9fd7
deleted new project
Mar 20, 2019
588c448
fixed tests since adding new file to unformatted project
Mar 20, 2019
438ed41
added a test for a file in the list that doesn't exist
Mar 20, 2019
a0803d5
ignore case when comparing paths
Mar 20, 2019
757adbd
break after finding file
Mar 20, 2019
b9c7008
convert loop to linq
Mar 20, 2019
39baef8
new resource missing from two xlf files
Mar 20, 2019
c1ec999
removed directory from test file path
Mar 20, 2019
94c32aa
use GetRelativePath to fix directory separators
Mar 21, 2019
6f19b3b
added test for directory separator insensitivity
Mar 21, 2019
13e72d9
moved fixing path separators to when the list is split
Mar 21, 2019
7c1aae1
removed failing test since code moved
Mar 21, 2019
d75a19c
make GetFileList internal for future test
Mar 21, 2019
825d7b5
added new test for directory separator insensitivity
Mar 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/CodeFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -160,7 +160,9 @@ void LogWorkspaceWarnings(object sender, WorkspaceDiagnosticEventArgs args)

if (filesToFormat != null)
{
var fileInArgumentList = filesToFormat.Any(path => document.FilePath.EndsWith(path, StringComparison.OrdinalIgnoreCase));
var fileInArgumentList = filesToFormat
.Select(path => Path.GetRelativePath(Environment.CurrentDirectory, path))
This conversation was marked as resolved.
Show resolved Hide resolved
.Any(relativePath => document.FilePath.EndsWith(relativePath, StringComparison.OrdinalIgnoreCase));

if (!fileInArgumentList)
{
Expand Down
17 changes: 17 additions & 0 deletions tests/CodeFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,22 @@ public async Task NoFilesFormattedWhenNotInList()
Assert.Equal(0, formatResult.FilesFormatted);
Assert.Equal(4, formatResult.FileCount);
}

[Fact]
public async Task FilesFormattedDirectorySeparatorInsensitive()
{
var logger = new TestLogger();
var path = Path.GetFullPath("tests/projects/for_code_formatter/unformatted_project/unformatted_project.csproj", SolutionPath);

var filePath = $"other_items{Path.DirectorySeparatorChar}OtherClass.cs";
var files = new[] {filePath};
var formatResult = await CodeFormatter.FormatWorkspaceAsync(logger, path, isSolution: false, logAllWorkspaceWarnings: false, saveFormattedFiles: false, filesToFormat: files, cancellationToken: CancellationToken.None);

var filePathAlt = $"other_items{Path.AltDirectorySeparatorChar}OtherClass.cs";
var filesAlt = new[] {filePathAlt};
var formatResultAlt = await CodeFormatter.FormatWorkspaceAsync(logger, path, isSolution: false, logAllWorkspaceWarnings: false, saveFormattedFiles: false, filesToFormat: filesAlt, cancellationToken: CancellationToken.None);

Assert.True(formatResult.FilesFormatted == formatResultAlt.FilesFormatted);
}
}
}