Skip to content

Commit

Permalink
Merge pull request #8 from ValentinVignal/v0.14.dev
Browse files Browse the repository at this point in the history
v0.14
  • Loading branch information
ValentinVignal authored Aug 1, 2022
2 parents cff945a + df6e681 commit 59af903
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ jobs:
name: Lint flutter code
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up Flutter
uses: subosito/flutter-action@v1
uses: subosito/flutter-action@v2
- run: flutter pub get
- name: Analyze Flutter
uses: ValentinVignal/action-dart-analyze@v0.13
uses: ValentinVignal/action-dart-analyze@v0.14
with:
fail-on: 'warning'
```
13 changes: 8 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16551,7 +16551,6 @@ function format(params) {
const lines = output.trim().split(/\r?\n/);
const errLines = errOutputs.trim().split(/\r?\n/);
const fileNotFormatted = new Set();
const currentWorkingDirectory = process.cwd();
for (const line of [...lines, ...errLines]) {
if (!line.startsWith('Changed')) {
continue;
Expand All @@ -16562,7 +16561,7 @@ function format(params) {
if (params.ignoredFiles.has(file)) {
continue;
}
if (params.modifiedFiles.has(path.join(currentWorkingDirectory, ActionOptions_1.actionOptions.workingDirectory, file))) {
if (params.modifiedFiles.has(path.join(ActionOptions_1.actionOptions.workingDirectory, file))) {
fileNotFormatted.add(file);
console.log(`::warning file=${file}:: ${file} is not formatted`);
}
Expand Down Expand Up @@ -17175,7 +17174,7 @@ const utils_1 = __nccwpck_require__(3030);
const path_1 = __importDefault(__nccwpck_require__(5622));
const ActionOptions_1 = __nccwpck_require__(3615);
/**
* Modified lines chunk of a file
* Modified lines chunk of a file.
*/
class FileLines {
constructor(params) {
Expand Down Expand Up @@ -17315,6 +17314,8 @@ class ModifiedFiles {
const files = yield this.getGithubFiles();
for (const file of files) {
this.files.set(path_1.default.join(process.env.GITHUB_WORKSPACE, file.filename), new ModifiedFile(file));
const modifiedFile = new ModifiedFile(file);
this.files.set(modifiedFile.name, modifiedFile);
}
this._resolveInit(true);
});
Expand Down Expand Up @@ -17360,10 +17361,12 @@ class ModifiedFiles {
});
}
/**
* Check whether a file is modified
* Check whether a file is modified.
*
* This needs to be the absolute path of the file (`'/home/runner/work/...'`).
*
* @param fileName
* @returns true if fileName is a modified file
* @returns `true` if {@link fileName} is a modified file.
*/
has(fileName) {
return this.files.has(fileName);
Expand Down
10 changes: 1 addition & 9 deletions src/format/Format.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
const mockPath = {
join: jest.fn(),
};

jest.mock('path', () => mockPath);

const mockActionOptions = {
actionOptions: {} as ActionOptions,
};
Expand Down Expand Up @@ -31,7 +25,7 @@ describe('Format', () => {
it('should concatenate the cwd to files from the format command to compare them with the modified files', async () => {
mockActionOptions.actionOptions = {
format: true,
workingDirectory: 'actionOptionWorkingDirectory',
workingDirectory: 'cwd/actionOptionWorkingDirectory',
failOn: FailOnEnum.Format,
} as ActionOptions;
const ignoredFiles: Partial<IgnoredFiles> = {
Expand All @@ -55,8 +49,6 @@ describe('Format', () => {
return ['cwd/actionOptionWorkingDirectory/lib/file_0.dart', 'cwd/actionOptionWorkingDirectory/lib/file_1.dart'].includes(file);
});

jest.spyOn(process, 'cwd').mockReturnValue('cwd');
mockPath.join.mockImplementation((...args: string[]) => args.join('/'));

const result = await format({
modifiedFiles: modifiedFiles as ModifiedFiles,
Expand Down
3 changes: 1 addition & 2 deletions src/format/Format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export async function format(params: { modifiedFiles: ModifiedFiles, ignoredFile
const lines = output.trim().split(/\r?\n/);
const errLines = errOutputs.trim().split(/\r?\n/);
const fileNotFormatted = new Set<string>();
const currentWorkingDirectory = process.cwd();

for (const line of [...lines, ...errLines]) {
if (!line.startsWith('Changed')) {
Expand All @@ -53,7 +52,7 @@ export async function format(params: { modifiedFiles: ModifiedFiles, ignoredFile
if (params.ignoredFiles.has(file)) {
continue;
}
if (params.modifiedFiles.has(path.join(currentWorkingDirectory, actionOptions.workingDirectory, file))) {
if (params.modifiedFiles.has(path.join(actionOptions.workingDirectory, file))) {
fileNotFormatted.add(file);
console.log(`::warning file=${file}:: ${file} is not formatted`);
}
Expand Down
15 changes: 11 additions & 4 deletions src/utils/ModifiedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface FileLinesInterface {
}

/**
* Modified lines chunk of a file
* Modified lines chunk of a file.
*/
class FileLines {
readonly start: number;
Expand All @@ -37,6 +37,9 @@ export interface ModifiedFileInterface {
* A modified file
*/
class ModifiedFile {
/**
* The file name from the root directory (`'lib/src/...'`).
*/
readonly name: string;
readonly deletions: FileLines[];
readonly additions: FileLines[];
Expand Down Expand Up @@ -182,6 +185,8 @@ export class ModifiedFiles {
const files = await this.getGithubFiles();
for (const file of files) {
this.files.set(path.join(process.env.GITHUB_WORKSPACE!, file.filename), new ModifiedFile(file));
const modifiedFile = new ModifiedFile(file);
this.files.set(modifiedFile.name, modifiedFile);
}
this._resolveInit(true);
}
Expand Down Expand Up @@ -234,10 +239,12 @@ export class ModifiedFiles {
}

/**
* Check whether a file is modified
*
* Check whether a file is modified.
*
* This needs to be the absolute path of the file (`'/home/runner/work/...'`).
*
* @param fileName
* @returns true if fileName is a modified file
* @returns `true` if {@link fileName} is a modified file.
*/
public has(fileName: string): boolean {
return this.files.has(fileName);
Expand Down

0 comments on commit 59af903

Please sign in to comment.