-
Notifications
You must be signed in to change notification settings - Fork 101
Opt-in Atom editor conversion #728
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
Changes from all commits
8b84a3d
b6affc8
1d5106f
1c20b2e
b470605
459981c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,10 @@ | |
"dependencies": { | ||
"chalk": "4.1.0", | ||
"commander": "6.1.0", | ||
"cson-parser": "^4.0.5", | ||
"eslint-config-prettier": "6.13.0", | ||
"glob": "7.1.6", | ||
"lodash": "^4.17.20", | ||
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. Psss, you could have used lodash-es which is tree-shakable hence reduces bundle size. 🍸 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. Aha! I can never keep track of which Lodash is the right one to use now 😄. Will do. 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. Hmm, https://www.npmjs.com/package/lodash-es is a year out of date 😕 ... I'll skip this for now, but if it ends up getting regularly published it'd be great to include. 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. Oh fun, this is an actively discussed topic: https://github.com/lodash/lodash/issues/4879 |
||
"minimatch": "3.0.4", | ||
"strip-json-comments": "3.1.1", | ||
"tslint": "6.1.3", | ||
|
@@ -28,6 +30,7 @@ | |
"@types/eslint-config-prettier": "6.11.0", | ||
"@types/glob": "7.1.3", | ||
"@types/jest": "26.0.14", | ||
"@types/lodash": "^4.14.162", | ||
"@types/minimatch": "3.0.3", | ||
"@types/node": "12.12.21", | ||
"@typescript-eslint/eslint-plugin": "4.4.1", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,137 +1,69 @@ | ||
import { ResultStatus, FailedResult } from "../../types"; | ||
import { convertEditorConfig, ConvertEditorConfigDependencies } from "./convertEditorConfig"; | ||
import { createEmptyEditorSettingConversionResults } from "./editorConversionResults.stubs"; | ||
import { EditorSetting } from "./types"; | ||
import { convertEditorConfig } from "./convertEditorConfig"; | ||
|
||
const stubPath = "./vscode/settings.json"; | ||
|
||
const stubSettings = { | ||
config: "./eslintrc.js", | ||
editor: "./my-editor/settings.json", | ||
config: ".eslintrc.js", | ||
}; | ||
|
||
const createStubDependencies = ( | ||
overrides: Partial<ConvertEditorConfigDependencies> = {}, | ||
): ConvertEditorConfigDependencies => ({ | ||
convertEditorSettings: jest.fn(), | ||
findEditorConfiguration: jest.fn().mockResolvedValue({}), | ||
reportEditorSettingConversionResults: jest.fn(), | ||
writeEditorConfigConversionResults: jest.fn().mockReturnValue(Promise.resolve()), | ||
...overrides, | ||
}); | ||
|
||
describe("convertEditorConfig", () => { | ||
it("returns a success result when there is no original configuration", async () => { | ||
// Arrange | ||
const dependencies = createStubDependencies({ | ||
findEditorConfiguration: async () => undefined, | ||
}); | ||
|
||
// Act | ||
const result = await convertEditorConfig(dependencies, stubSettings); | ||
|
||
// Assert | ||
expect(result).toEqual({ | ||
status: ResultStatus.Succeeded, | ||
}); | ||
}); | ||
|
||
it("returns the failure result when finding the original configurations fails", async () => { | ||
it("returns an error when reading the file fails", async () => { | ||
// Arrange | ||
const error = new Error(); | ||
const findError: FailedResult = { | ||
errors: [error], | ||
status: ResultStatus.Failed, | ||
const error = new Error("Oh no"); | ||
const dependencies = { | ||
fileSystem: { | ||
readFile: jest.fn().mockResolvedValue(error), | ||
writeFile: jest.fn(), | ||
}, | ||
}; | ||
|
||
const dependencies = createStubDependencies({ | ||
findEditorConfiguration: async () => ({ | ||
configPath: "", | ||
result: error, | ||
}), | ||
}); | ||
|
||
// Act | ||
const result = await convertEditorConfig(dependencies, stubSettings); | ||
const result = await convertEditorConfig(dependencies, jest.fn(), stubPath, stubSettings); | ||
|
||
// Assert | ||
expect(result).toEqual(findError); | ||
expect(result).toEqual(error); | ||
}); | ||
|
||
it("returns the failure result when writing to the configuration file fails", async () => { | ||
it("returns an error when writing to a file fails", async () => { | ||
// Arrange | ||
const fileWriteError = new Error(); | ||
const dependencies = createStubDependencies({ | ||
writeEditorConfigConversionResults: jest.fn().mockResolvedValueOnce(fileWriteError), | ||
const originalFileContents = "Hello"; | ||
const error = new Error("Oh no!"); | ||
const converter = (input: string) => ({ | ||
contents: `${input} world!`, | ||
missing: [], | ||
}); | ||
|
||
// Act | ||
const result = await convertEditorConfig(dependencies, stubSettings); | ||
|
||
// Assert | ||
expect(result).toEqual({ | ||
errors: [fileWriteError], | ||
status: ResultStatus.Failed, | ||
}); | ||
}); | ||
|
||
it("converts conversion results when finding the original configurations succeeds", async () => { | ||
// Arrange | ||
const originalConfig = { | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
const dependencies = { | ||
fileSystem: { | ||
readFile: jest.fn().mockResolvedValue(originalFileContents), | ||
writeFile: jest.fn().mockResolvedValue(error), | ||
}, | ||
}; | ||
|
||
const dependencies = createStubDependencies({ | ||
findEditorConfiguration: jest.fn().mockResolvedValue({ | ||
result: originalConfig, | ||
}), | ||
}); | ||
|
||
// Act | ||
await convertEditorConfig(dependencies, stubSettings); | ||
const result = await convertEditorConfig(dependencies, converter, stubPath, stubSettings); | ||
|
||
// Assert | ||
expect(dependencies.convertEditorSettings).toHaveBeenCalledWith( | ||
originalConfig, | ||
stubSettings, | ||
); | ||
expect(result).toEqual(error); | ||
}); | ||
|
||
it("reports conversion results when settings are converted successfully", async () => { | ||
it("returns the conversion data when writing to a file succeeds", async () => { | ||
// Arrange | ||
const conversionResults = createEmptyEditorSettingConversionResults({ | ||
converted: new Map<string, EditorSetting>([ | ||
[ | ||
"tslint-editor-setting-one", | ||
{ | ||
editorSettingName: "tslint-editor-setting-one", | ||
value: 42, | ||
}, | ||
], | ||
]), | ||
}); | ||
|
||
const dependencies = createStubDependencies({ | ||
convertEditorSettings: jest.fn().mockReturnValue(conversionResults), | ||
const originalFileContents = "Hello"; | ||
const converter = (input: string) => ({ | ||
contents: `${input} world!`, | ||
missing: [], | ||
}); | ||
const dependencies = { | ||
fileSystem: { | ||
readFile: jest.fn().mockResolvedValue(originalFileContents), | ||
writeFile: jest.fn().mockResolvedValue(undefined), | ||
}, | ||
}; | ||
|
||
// Act | ||
await convertEditorConfig(dependencies, stubSettings); | ||
|
||
// Assert | ||
expect(dependencies.reportEditorSettingConversionResults).toHaveBeenCalledWith( | ||
conversionResults, | ||
); | ||
}); | ||
|
||
it("returns a successful result when finding the original configurations succeeds", async () => { | ||
// Arrange | ||
const dependencies = createStubDependencies(); | ||
|
||
// Act | ||
const result = await convertEditorConfig(dependencies, stubSettings); | ||
const result = await convertEditorConfig(dependencies, converter, stubPath, stubSettings); | ||
|
||
// Assert | ||
expect(result).toEqual({ | ||
status: ResultStatus.Succeeded, | ||
}); | ||
expect(result).toEqual(converter(originalFileContents)); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.
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 get an error
npm ERR! 404 Not Found - GET http://my-registry-url/coffeescript/-/coffeescript-1.12.8.tgz
during installation on Windows. It comes fromcson-parser
. There are some mentions of this problem, for example at jashkenas/coffeescript/issues/4805, but it's not clear how to fix it while installing Angular Eslint withng add @angular-eslint/schematics
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.
Hello, can you open a new issue in order to track the error with Angular ESLint + this package? Thank you :)
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.
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.
Thank you, we will look into these and provide a proper fix soon.