-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat: print clang-format output #186
Merged
+239
−6
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
3bdc619
Started working using regex
lee-tammy ab8bc97
Working on apply patches in jsdiff
lee-tammy 0fa2476
Able to separate string into multiple diffs and print them
lee-tammy 314e3ca
Added comments and changed formatting -- Has special character bug
lee-tammy d692f24
Changed output formatting -- does not support utf8 characters
lee-tammy 7f34080
Revert changes in a comment
lee-tammy bb5f697
Changed original substring function to special substring that counts …
lee-tammy 22933d6
Added dependencies
lee-tammy 36d0299
Made some changes
lee-tammy 13a78ad
Split functions and added comments -- possible error when directory i…
lee-tammy ff94ab0
Forgot to add diff dependency
lee-tammy e4d1945
Added some comments and added some error checks
lee-tammy 5c6f5f5
Updated regex -- should work on node 6 now
lee-tammy 7844b05
Added a test for formating
lee-tammy b46b96e
Commit for merge
lee-tammy b7f7c31
Merged conflicts
lee-tammy 850a455
Added tests and made minor changes
lee-tammy 9b4521a
Fixed comment
lee-tammy 8f02bce
Used lint and format
lee-tammy a37c01b
Changed existing tests
lee-tammy ddd5d81
Removed Logger import statement b/c it is not used anymore
lee-tammy d8575d4
Fixed tests and added one to check for error
lee-tammy bc47938
Fixed line over 80 chars
lee-tammy b57c458
forgot to run lint
lee-tammy 69b3211
Merge branch 'master' into print-format-lines-v3
kjin 2b80caa
Merge branch 'master' into print-format-lines-v3
kjin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added a test for formating
commit 7844b0575e98d4fb423fc19cf8fc1e354d4013b0
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,11 @@ import {nop} from '../src/util'; | |
import {withFixtures} from './fixtures'; | ||
|
||
// clang-format won't pass this code because of trailing spaces. | ||
const BAD_CODE = 'export const foo = [ 2 ];'; | ||
const GOOD_CODE = 'export const foo = [2];'; | ||
const BAD_CODE = '//🦄\nexport const foo = [ \"2\" ];'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we discussed in person, let's have the unicorn be in its own test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
const GOOD_CODE = '//🦄\nexport const foo = [\'2\'];'; | ||
|
||
const CLANG_FORMAT_MESSAGE = | ||
'clang-format reported errors... run `gts fix` to address.'; | ||
|
||
const OPTIONS: Options = { | ||
gtsRootDir: path.resolve(__dirname, '../..'), | ||
|
@@ -210,3 +213,32 @@ test.serial('format should return error from failed spawn', async t => { | |
format.clangFormat.spawnClangFormat = original; | ||
}); | ||
}); | ||
|
||
test.serial( | ||
'format should print suggestions for fixes for ill-formatted file', t => { | ||
return withFixtures( | ||
{ | ||
'tsconfig.json': JSON.stringify({files: ['a.ts']}), | ||
'a.ts': BAD_CODE | ||
}, | ||
async () => { | ||
let output = ''; | ||
const newLogger = Object.assign({}, OPTIONS.logger, { | ||
log: (n: string) => { | ||
output += n; | ||
} | ||
}); | ||
const options = Object.assign({}, OPTIONS, {logger: newLogger}); | ||
|
||
await format.format(options, [], false); | ||
if (output.search(CLANG_FORMAT_MESSAGE) === -1) { | ||
t.fail('Does not print ...run \'gts fix\'...'); | ||
} else if ( | ||
output.indexOf('+export const foo = [\'2\'];') === -1 || | ||
output.indexOf('-export const foo = [ \"2\" ];') === -1 || | ||
output.indexOf('🦄') === -1) { | ||
t.fail('Output messages and suggested fix are incorrect'); | ||
} | ||
t.pass(); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: It wasn't immediately obvious to me that
xmlLines.length - 2
is correct. If you definexmlLines
asfileXML.trim().split('\n')
then it will guarantee one element per non-empty line, so you could probably usexmlLines.length - 1
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done