-
Notifications
You must be signed in to change notification settings - Fork 89
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
feat: show diff after sorting #268
base: main
Are you sure you want to change the base?
feat: show diff after sorting #268
Conversation
cli.js
Outdated
const diff = Diff.diffLines(packageJson, sorted) | ||
diff.forEach((part) => { | ||
const color = part.added ? 'green' : part.removed ? 'red' : 'grey' | ||
process.stderr.write(part.value[color]) |
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.
I prefer use a small color lib like yoctocolors
instead of extending String.prototype
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.
@fisker
Thanks for the review.
I prefer use a small color lib like yoctocolors instead
Since require()
was not supported for yoctocolors, I did not introduce it, but introduced picocolors.
Snapshot changes have also occurred with the lib changes, so we have updated it again.
cli.js
Outdated
? pc.green(part.value) | ||
: part.removed | ||
? pc.red(part.value) | ||
: pc.gray(part.value) |
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.
Put +
/-
before the line? For environment doesn't support color.
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.
Put
+/-
before the line?
I agree. +/- is now displayed before the line.
Result
Sorting items
If there are unnecessary row
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.
Forgot to commit?
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.
Sorry...
I will contact you again when I push commit.
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.
Please also add a
for lines without a -
or +
so that the file is all inline.
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.
Should we add space after +
?
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.
package.json are special normally they are already indented.
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.
Forgot to commit?
I've pushed the current one.
I will check again on the comments I received.
Co-authored-by: Keith Cirkel <[email protected]>
When I resolve the conflict in #269 and commit, I get an error that there is no eslint configuration file and I can't commit, should I mention it issues? error log ❯ git commit -m 'chore: conflict resolution'
npm WARN config init.author.name Use `--init-author-name` instead.
npm WARN config init.author.email Use `--init-author-email` instead.
npm WARN config init.author.url Use `--init-author-url` instead.
> [email protected] test
> ava && dtslint --localTs node_modules/typescript/lib
(⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠇ : timing config:load:flatten Completed in 1ms
✔ eslint › eslintIgnoretiming config:load:flatten Completed in 1ms
✔ eslint › eslintConfig
✔ eslint › eslintConfig.rules
✔ eslint › eslintConfig.env
✔ eslint › eslintConfig.globals
✔ eslint › eslintConfig.parserOptions
✔ eslint › eslintConfig.settings
✔ eslint › eslintConfig.parser
✔ eslint › eslintConfig.plugins
✔ eslint › eslintConfig.extends
✔ eslint › eslintConfig.processor
✔ eslint › eslintConfig.noInlineConfig
✔ eslint › eslintConfig.reportUnusedDisableDirectives
✔ eslint › eslintConfig.override[]
✔ options › options.sortOrder
✔ options › options.sortOrder prepend
✔ options › options.sortOrder effect
✔ options › options.sortOrder function
✔ options › options.sortOrder with private key
✔ prettier › prettier
✔ prettier › prettier.overrides[]
✔ prettier › prettier.overrides[].options
✔ deps › resolutions
✔ deps › dependencies
✔ deps › devDependencies
✔ deps › peerDependencies
✔ deps › optionalDependencies
✔ deps › bundledDependencies
✔ deps › bundleDependencies
✔ deps › extensionPack
✔ deps › extensionDependencies
✔ deps › peerDependenciesMeta
✔ deps › dependenciesMeta
✔ main › main⠂⠂⠂⠂) ⠇ : timing config:load:flatten Completed in 1ms
✔ main › default sortOrder
✔ main › private keys
✔ scripts › scripts when npm-run-all is not a dev dependencyin 1ms
✔ scripts › scripts when npm-run-all is a dev dependency
✔ scripts › betterScripts when npm-run-all is not a dev dependency
✔ scripts › betterScripts when npm-run-all is a dev dependency
✔ fields › $schema ⠇ : timing config:load:flatten Completed in 1ms
✔ fields › name
✔ fields › displayName
✔ fields › version
✔ fields › description
✔ fields › sideEffects
✔ fields › qna
✔ fields › publisher
✔ fields › type
✔ fields › main
✔ fields › svelte
✔ fields › umd:main
✔ fields › jsdelivr
✔ fields › unpkg
✔ fields › module
✔ fields › source
✔ fields › jsnext:main
✔ fields › browser
✔ fields › react-nativetiming config:load:flatten Completed in 1ms
✔ fields › types
✔ fields › typesVersions
✔ fields › typings
✔ fields › style
✔ fields › example
✔ fields › examplestyle
✔ fields › assets
✔ fields › man
✔ fields › workspaces
✔ fields › pre-commit
✔ fields › browserslist
✔ fields › stylelint
✔ fields › flat
✔ fields › packageManager
✔ fields › os
✔ fields › cpu
✔ fields › icon
✔ fields › preview
✔ fields › markdown
✔ fields › bin
✔ fields › contributes
✔ fields › commitlint
✔ fields › config
✔ fields › nodemonConfigiming config:load:flatten Completed in 1ms
✔ fields › browserify
✔ fields › babel
✔ fields › xo
✔ fields › ava
✔ fields › jest
✔ fields › mocha
✔ fields › nyc
✔ fields › c8
✔ fields › engines
✔ fields › engineStrict
✔ fields › preferGlobal
✔ fields › publishConfig
✔ fields › galleryBanner
✔ fields › remarkConfig
✔ fields › release
✔ fields › npmpkgjsonlint
✔ fields › npmPackageJsonLintConfig
✔ fields › npmpackagejsonlint
✔ fields › keywords
✔ fields › files
✔ fields › activationEvents
✔ fields › categories
✔ fields › husky
✔ fields › binary
✔ fields › bugs
✔ fields › repository
✔ fields › funding
✔ fields › license
✔ fields › author
✔ fields › directories
✔ fields › volta
✔ fields › contributors
✔ fields › badges
✔ cli › cli (233ms)
✔ cli › run `cli` on 2 bad files (195ms)
✔ cli › run `cli --check` on 1 bad file (206ms)
✔ cli › run `cli` on 1 bad file (214ms)
✔ cli › run `cli -c` with no patterns (223ms)
✔ cli › run `cli --check` with no patterns (238ms)
✔ cli › run `cli` with no patterns (252ms)
✔ cli › run `cli --check` on 2 bad files (223ms)n Completed in 1ms
✔ cli › run `cli` on duplicate patterns (109ms)en Completed in 1ms
✔ cli › run `cli --check` on duplicate patterns (106ms)
✔ cli › run `cli` on 2 good files and 2 bad files (218ms)
✔ cli › run `cli` on none exists file (132ms)
✔ cli › run `cli --check` on none exists file (123ms)
✔ cli › run `cli --check` on 2 good files and 2 bad files (193ms)
✔ white-space › white space
─⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠇ : timing config:load:flatten Completed in 1ms
131 tests passed
npm WARN config init.author.name Use `--init-author-name` instead.
npm WARN config init.author.email Use `--init-author-email` instead.
npm WARN config init.author.url Use `--init-author-url` instead.
✔ Preparing lint-staged...
✔ Hiding unstaged changes to partially staged files...
⚠ Running tasks for staged files...
❯ package.json — 21 files
❯ *.js — 12 files
✖ eslint --fix [FAILED]
↓ *.ts — no files [SKIPPED]
✔ package.json — 1 file
↓ Skipped because of errors from tasks. [SKIPPED]
↓ Skipped because of errors from tasks. [SKIPPED]
✔ Reverting to original state because of errors...
✔ Cleaning up temporary files...
✖ eslint --fix:
Oops! Something went wrong! :(
ESLint: 7.32.0
ESLint couldn't find a configuration file. To set up a configuration file for this project, please run:
eslint --init
ESLint looked for configuration files in /filepath/sort-package-json and its ancestors. If it found none, it then looked in your home directory.
If you think you already have a configuration file or if you need more help, please stop by the ESLint chat room: https://eslint.org/chat/help
husky - pre-commit hook exited with code 1 (error) |
Something wrong in husky script, I guess. I'll fix it. |
Conflicts have been corrected. |
@miwashutaro0611 Tests are failing. |
@fisker The following is the result of a local demonstration. Git status❯ git status
On branch feature/chore-install-jsdiff
nothing to commit, working tree clean
❯ git log -n 1
commit 113ab6e5ca4c620f750ecfe5fad08a8ea6d2edd6 (HEAD -> feature/chore-install-jsdiff, origin/feature/chore-install-jsdiff)
Merge: 885ad4b c1e1a14
Author: miwashutaro0611 <[email protected]>
Date: Sat Oct 1 12:57:46 2022 +0900
chore: conflict resolution Node version❯ node -v
v16.15.1 Local npm test command resultsResult `npm run test`❯ npm run test
npm WARN config init.author.name Use `--init-author-name` instead.
npm WARN config init.author.email Use `--init-author-email` instead.
npm WARN config init.author.url Use `--init-author-url` instead.
> [email protected] test
> ava && dtslint --localTs node_modules/typescript/lib
(⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠇ : timing config:load:flatten Completed in 2ms
✔ options › options.sortOrder config:load:flatten Completed in 2ms
✔ options › options.sortOrder prepend
✔ options › options.sortOrder effect
✔ options › options.sortOrder function
✔ options › options.sortOrder with private key
✔ main › main⠂⠂⠂⠂) ⠇ : timing config:load:flatten Completed in 2ms
✔ main › default sortOrder
✔ main › private keys
✔ scripts › scripts when npm-run-all is not a dev dependency
✔ scripts › scripts when npm-run-all is a dev dependency
✔ scripts › betterScripts when npm-run-all is not a dev dependency
✔ scripts › betterScripts when npm-run-all is a dev dependency
✔ eslint › eslintIgnore
✔ eslint › eslintConfig
✔ eslint › eslintConfig.rules
✔ eslint › eslintConfig.env
✔ eslint › eslintConfig.globals
✔ eslint › eslintConfig.parserOptions
✔ eslint › eslintConfig.settings
✔ eslint › eslintConfig.parser
✔ eslint › eslintConfig.plugins
✔ eslint › eslintConfig.extends
✔ eslint › eslintConfig.processor
✔ eslint › eslintConfig.noInlineConfig
✔ eslint › eslintConfig.reportUnusedDisableDirectives
✔ eslint › eslintConfig.override[]
✔ deps › resolutions
✔ deps › dependencies
✔ deps › devDependencies
✔ deps › peerDependencies
✔ deps › optionalDependencies
✔ deps › bundledDependencies
✔ deps › bundleDependencies
✔ deps › extensionPack
✔ deps › extensionDependencies
✔ deps › peerDependenciesMeta
✔ deps › dependenciesMeta
✔ fields › $schema
✔ fields › name
✔ fields › displayName
✔ fields › version
✔ fields › description
✔ fields › sideEffects
✔ fields › qna
✔ fields › publisher : timing config:load:flatten Completed in 2ms
✔ fields › type
✔ fields › main
✔ fields › svelte
✔ fields › umd:main
✔ fields › jsdelivr
✔ fields › unpkg
✔ fields › module
✔ fields › source
✔ fields › jsnext:main
✔ fields › browser
✔ fields › react-native
✔ fields › types
✔ fields › typesVersions
✔ fields › typings
✔ fields › style
✔ fields › example
✔ fields › examplestyle
✔ fields › assets
✔ fields › man
✔ fields › workspaces
✔ fields › pre-commit
✔ fields › browserslist
✔ fields › stylelint
✔ fields › flat
✔ fields › packageManager
✔ fields › os
✔ fields › cpu
✔ fields › icon
✔ fields › preview
✔ fields › markdown
✔ fields › bin
✔ fields › contributes
✔ fields › commitlint
✔ fields › config
✔ fields › nodemonConfig
✔ fields › browserify
✔ fields › babel
✔ fields › xo
✔ fields › ava
✔ fields › jest
✔ fields › mocha
✔ fields › nyc
✔ fields › c8
✔ fields › engines
✔ fields › engineStrict
✔ fields › preferGlobal
✔ fields › publishConfig
✔ fields › galleryBanner
✔ fields › remarkConfig
✔ fields › release
✔ fields › npmpkgjsonlint
✔ fields › npmPackageJsonLintConfig
✔ fields › npmpackagejsonlint
✔ fields › keywords
✔ fields › files
✔ fields › activationEvents
✔ fields › categories
✔ fields › husky
✔ fields › binary
✔ fields › bugs
✔ fields › repository
✔ fields › funding
✔ fields › license
✔ fields › author
✔ fields › directories
✔ fields › volta
✔ fields › contributors
✔ fields › badges
✔ prettier › prettier
✔ prettier › prettier.overrides[]
✔ prettier › prettier.overrides[].options
✔ cli › cli (203ms)⠇ : timing config:load:flatten Completed in 2ms
✔ white-space › white spaceng config:load:flatten Completed in 2ms
✔ cli › run `cli --check` on 1 bad file (223ms)
✔ cli › run `cli` on 1 bad file (233ms)
✔ cli › run `cli -c` with no patterns (243ms)
✔ cli › run `cli --check` with no patterns (252ms)
✔ cli › run `cli` with no patterns (264ms)
✔ cli › run `cli` on 2 bad files (223ms)
✔ cli › run `cli --check` on 2 bad files (184ms)
✔ cli › run `cli` on 2 good files and 2 bad files (161ms)ed in 2ms
✔ cli › run `cli` on none exists file (128ms)
✔ cli › run `cli --check` on 2 good files and 2 bad files (158ms)
✔ cli › run `cli --check` on none exists file (111ms)
✔ cli › run `cli` on duplicate patterns (119ms)
✔ cli › run `cli --check` on duplicate patterns (115ms)
─⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠇ : timing config:load:flatten Completed in 2ms
131 tests passed Result `npm run test-coverage`❯ npm run test-coverage
npm WARN config init.author.name Use `--init-author-name` instead.
npm WARN config init.author.email Use `--init-author-email` instead.
npm WARN config init.author.url Use `--init-author-url` instead.
> [email protected] test-coverage
> nyc ava
(⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠇ : timing config:load:flatten Completed in 3ms
✔ eslint › eslintIgnoretiming config:load:flatten Completed in 3ms
✔ eslint › eslintConfig
✔ eslint › eslintConfig.rules
✔ eslint › eslintConfig.env
✔ eslint › eslintConfig.globals
✔ eslint › eslintConfig.parserOptions
✔ eslint › eslintConfig.settings
✔ eslint › eslintConfig.parser
✔ eslint › eslintConfig.plugins
✔ eslint › eslintConfig.extends
✔ eslint › eslintConfig.processor
✔ eslint › eslintConfig.noInlineConfig
✔ eslint › eslintConfig.reportUnusedDisableDirectives
✔ eslint › eslintConfig.override[]
✔ scripts › scripts when npm-run-all is not a dev dependencyin 3ms
✔ scripts › scripts when npm-run-all is a dev dependency
✔ scripts › betterScripts when npm-run-all is not a dev dependency
✔ scripts › betterScripts when npm-run-all is a dev dependency
✔ cli › cli (378ms)
✔ prettier › prettier: timing config:load:flatten Completed in 3ms
✔ prettier › prettier.overrides[]
✔ prettier › prettier.overrides[].options
✔ main › main
✔ main › default sortOrder
✔ main › private keys
✔ cli › run `cli` with no patterns (597ms)flatten Completed in 3ms
✔ deps › resolutions : timing config:load:flatten Completed in 3ms
✔ deps › dependencies
✔ deps › devDependencies
✔ deps › peerDependencies
✔ deps › optionalDependencies
✔ deps › bundledDependencies
✔ deps › bundleDependencies
✔ deps › extensionPack
✔ deps › extensionDependencies
✔ deps › peerDependenciesMeta
✔ deps › dependenciesMeta
✔ cli › run `cli --check` with no patterns (627ms)
✔ cli › run `cli --check` on 2 good files and 2 bad files (439ms)s
✔ cli › run `cli -c` with no patterns (652ms)
✔ options › options.sortOrder config:load:flatten Completed in 3ms
✔ options › options.sortOrder prepend
✔ options › options.sortOrder effect
✔ options › options.sortOrder function
✔ options › options.sortOrder with private key
✔ cli › run `cli` on 1 bad file (800ms)ad:flatten Completed in 3ms
✔ fields › $schema ⠇ : timing config:load:flatten Completed in 3ms
✔ fields › name
✔ fields › displayName
✔ fields › version
✔ fields › description
✔ fields › sideEffects
✔ fields › qna
✔ fields › publisher
✔ fields › type
✔ fields › main
✔ fields › svelte
✔ fields › umd:main
✔ fields › jsdelivr
✔ fields › unpkg
✔ fields › module
✔ fields › source
✔ fields › jsnext:main
✔ fields › browser
✔ fields › react-native
✔ fields › types
✔ fields › typesVersions
✔ fields › typings
✔ fields › style
✔ fields › example
✔ fields › examplestyle
✔ fields › assets
✔ fields › man
✔ fields › workspaces
✔ fields › pre-commit
✔ fields › browserslist
✔ fields › stylelint
✔ fields › flat
✔ fields › packageManager
✔ fields › os
✔ fields › cpu
✔ fields › icon
✔ fields › preview
✔ fields › markdown
✔ fields › bin
✔ fields › contributes
✔ fields › commitlint
✔ fields › config
✔ fields › nodemonConfig
✔ fields › browserify
✔ fields › babel
✔ fields › xo
✔ fields › ava
✔ fields › jest
✔ fields › mocha
✔ fields › nyc
✔ fields › c8
✔ fields › engines
✔ fields › engineStrict
✔ fields › preferGlobal
✔ fields › publishConfig
✔ fields › galleryBanner
✔ fields › remarkConfig
✔ fields › release
✔ fields › npmpkgjsonlint
✔ fields › npmPackageJsonLintConfig
✔ fields › npmpackagejsonlint
✔ fields › keywords
✔ fields › files
✔ fields › activationEvents
✔ fields › categories
✔ fields › husky
✔ fields › binary
✔ fields › bugs
✔ fields › repository
✔ fields › funding
✔ fields › license
✔ fields › author
✔ fields › directories
✔ fields › volta
✔ fields › contributors
✔ fields › badges
✔ cli › run `cli` on none exists file (703ms)tten Completed in 3ms
✔ cli › run `cli` on duplicate patterns (658ms)
✔ cli › run `cli --check` on 1 bad file (906ms)en Completed in 3ms
✔ cli › run `cli` on 2 good files and 2 bad files (757ms)
✔ cli › run `cli` on 2 bad files (780ms)
✔ cli › run `cli --check` on 2 bad files (777ms)
✔ cli › run `cli --check` on none exists file (744ms)
✔ cli › run `cli --check` on duplicate patterns (665ms)eted in 3ms
✔ white-space › white spaceng config:load:flatten Completed in 3ms
─⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠇ : timing config:load:flatten Completed in 3ms
131 tests passed
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|------------------- |
Strange, but fixed 8f437e6 |
diff.forEach((part) => { | ||
const partLineList = part.value.split('\n') | ||
partLineList.forEach((line, index) => { | ||
if ((part.added || part.removed) && index === partLineList.length - 1) | ||
return | ||
const colorValue = part.added | ||
? yoctocolors.green(`+${line}\n`) | ||
: part.removed | ||
? yoctocolors.red(`-${line}\n`) | ||
: yoctocolors.gray(` ${line}\n`) | ||
process.stderr.write(colorValue) | ||
}) |
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.
We can use console.error(diff.map(...))
here.
@@ -34,6 +36,20 @@ files.forEach((file) => { | |||
} else { | |||
fs.writeFileSync(file, sorted, 'utf8') | |||
console.log(`${file} is sorted!`) | |||
const diff = diffLines(packageJson, sorted) | |||
diff.forEach((part) => { | |||
const partLineList = part.value.split('\n') |
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.
I think the EOL can be \r
or \r\n
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.
I see.
Thank you for the information on how to respond.
Fixes #48
Changes
diff-result.mov