Skip to content

chore: update eslint-config-atomic #145

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

Merged
merged 6 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 12 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
{
"extends": "eslint-config-atomic/strict",
"extends": ["eslint-config-atomic/strict", "plugin:chai-friendly/recommended"],
"ignorePatterns": ["build/", "node_modules/"],
"rules": {
"no-eq-null": "warn",
"eqeqeq": "warn",
"no-empty-function": "warn",
"class-methods-use-this": "warn",
"default-case": "warn",
"no-new": "warn",
"no-shadow": "warn",
"no-invalid-this": "warn",
"require-await": "warn",
"no-useless-constructor": "warn",
"@typescript-eslint/ban-types": [
"error",
{
Expand All @@ -16,7 +26,7 @@
"allowArgumentsExplicitlyTypedAsAny": true
}
],
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": [
"error",
Expand Down
9 changes: 5 additions & 4 deletions lib/adapters/command-execution-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export default class CommandExecutionAdapter {
this.commandsCustomCallbacks.set(command, callback)
}

public static async executeCommand(
/** Returns a {Promise} */
public static executeCommand(
connection: LanguageClientConnection,
command: string,
commandArgs?: any[]
Expand All @@ -23,13 +24,13 @@ export default class CommandExecutionAdapter {
const commandCustomCallback = this.commandsCustomCallbacks.get(command)

return commandCustomCallback !== undefined
? await commandCustomCallback(executeCommandParams)
: await connection.executeCommand(executeCommandParams)
? commandCustomCallback(executeCommandParams)
: connection.executeCommand(executeCommandParams)
}

private static createExecuteCommandParams(command: string, commandArgs?: any[]): ExecuteCommandParams {
return {
command: command,
command,
arguments: commandArgs,
}
}
Expand Down
12 changes: 7 additions & 5 deletions lib/adapters/outline-view-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ export default class OutlineViewAdapter {
* @returns An {OutlineTree} containing the given symbols that the Outline View can display.
*/
public static createOutlineTrees(symbols: SymbolInformation[]): atomIde.OutlineTree[] {
symbols.sort((a, b) =>
a.location.range.start.line === b.location.range.start.line
? a.location.range.start.character - b.location.range.start.character
: a.location.range.start.line - b.location.range.start.line
)
symbols.sort((a, b) => {
if (a.location.range.start.line === b.location.range.start.line) {
return a.location.range.start.character - b.location.range.start.character
} else {
return a.location.range.start.line - b.location.range.start.line
}
})

// Temporarily keep containerName through the conversion process
// Also filter out symbols without a name - it's part of the spec but some don't include it
Expand Down
2 changes: 2 additions & 0 deletions lib/auto-languageclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,9 @@ export default class AutoLanguageClient {
lsProcess.on("close", (code, signal) => this.onSpawnClose(code, signal))
lsProcess.on("disconnect", () => this.onSpawnDisconnect())
lsProcess.on("exit", (code, signal) => this.onSpawnExit(code, signal))
// eslint-disable-next-line chai-friendly/no-unused-expressions
lsProcess.stderr?.setEncoding("utf8")
// eslint-disable-next-line chai-friendly/no-unused-expressions
lsProcess.stderr?.on("data", (chunk: Buffer) => this.onSpawnStdErrData(chunk, projectPath))
}

Expand Down
2 changes: 2 additions & 0 deletions lib/download-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ async function streamWithProgress(

// eslint-disable-next-line no-constant-condition
while (true) {
// TODO use Promise.all
// eslint-disable-next-line no-await-in-loop
const result = await reader.read()
if (result.done) {
if (progressCallback != null) {
Expand Down
3 changes: 2 additions & 1 deletion lib/server-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ export class ServerManager {
if (startingPromise) {
return startingPromise
}

// TODO remove eslint-disable
// eslint-disable-next-line no-return-await
return shouldStart && this._startForEditor(textEditor) ? await this.startServer(finalProjectPath) : null
}

Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
"@types/mocha": "^8.2.0",
"@types/node": "14.14.22",
"@types/sinon": "^9.0.10",
"@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/parser": "^4.14.1",
"chai": "^4.2.0",
"eslint": "^7.18.0",
"eslint-config-atomic": "1.10.1",
"eslint-config-atomic": "^1.14.0",
"eslint-plugin-chai-friendly": "^0.6.0",
"mocha": "^8.2.1",
"mocha-appveyor-reporter": "^0.4.2",
"shx": "^0.3.3",
Expand Down
26 changes: 19 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/adapters/apply-edit-adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const TEST_PATH4 = normalizeDriveLetterName(path.join(__dirname, "test4.txt"))

function normalizeDriveLetterName(filePath: string): string {
if (process.platform === "win32") {
return filePath.replace(/^([a-z]):/, ([driveLetter]) => driveLetter.toUpperCase() + ":")
return filePath.replace(/^([a-z]):/, ([driveLetter]) => `${driveLetter.toUpperCase()}:`)
} else {
return filePath
}
Expand Down
10 changes: 5 additions & 5 deletions test/adapters/autocomplete-adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("AutoCompleteAdapter", () => {
type getSuggestionParams = Parameters<typeof autoCompleteAdapter.getSuggestions>

/** Function that stubs `server.connection.completion` and returns the `autoCompleteAdapter.getSuggestions(...)` */
async function getSuggestionsMock(
function getSuggestionsMock(
items: CompletionItem[],
request: getSuggestionParams[1],
onDidConvertCompletionItem?: getSuggestionParams[2],
Expand Down Expand Up @@ -288,7 +288,7 @@ describe("AutoCompleteAdapter", () => {

it("respects onDidConvertCompletionItem", async () => {
const results = await getSuggestionsMock([{ label: "label" }], createRequest({}), (c, a, r) => {
;(a as ac.TextSuggestion).text = c.label + " ok"
;(a as ac.TextSuggestion).text = `${c.label} ok`
a.displayText = r.scopeDescriptor.getScopesArray()[0]
})

Expand Down Expand Up @@ -448,7 +448,7 @@ describe("AutoCompleteAdapter", () => {
expect(result.replacementPrefix).equals("")
})

describe("applies changes from TextEdit to text", async () => {
describe("applies changes from TextEdit to text", () => {
const customRequest = createRequest({ prefix: "", position: new Point(0, 10) })
customRequest.editor.setText("foo #align bar")

Expand All @@ -473,7 +473,7 @@ describe("AutoCompleteAdapter", () => {
expect((results[0] as TextSuggestion).customReplacmentPrefix).equals("#align")
})

describe("applies the change if shouldReplace is true", async () => {
describe("applies the change if shouldReplace is true", () => {
it("1", async () => {
const results = await getSuggestionsMock(
[
Expand Down Expand Up @@ -575,7 +575,7 @@ describe("AutoCompleteAdapter", () => {
})
})

describe("applies the change if shouldReplace is false", async () => {
describe("applies the change if shouldReplace is false", () => {
it("1", async () => {
const results = await getSuggestionsMock(
[
Expand Down
2 changes: 1 addition & 1 deletion test/adapters/code-action-adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("CodeActionAdapter", () => {
expect((languageClient as any).codeAction.called).to.be.true
const args = (languageClient as any).codeAction.getCalls()[0].args
const params: ls.CodeActionParams = args[0]
expect(params.textDocument.uri).to.equal("file://" + testPath)
expect(params.textDocument.uri).to.equal(`file://${testPath}`)
expect(params.range).to.deep.equal({
start: { line: 1, character: 2 },
end: { line: 3, character: 4 },
Expand Down
10 changes: 6 additions & 4 deletions test/adapters/show-document-adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ import { createSpyConnection } from "../helpers"

describe("ShowDocumentAdapter", () => {
describe("can attach to a server", () => {
it("subscribes to onShowDocument", async () => {
it("subscribes to onShowDocument", () => {
const connection = createSpyConnection()
const lcc = new LanguageClientConnection(connection)

const spy = sinon.spy()
lcc["_onRequest"] = spy
// eslint-disable-next-line dot-notation
lcc["_onRequest"] = spy // private method access

ShowDocumentAdapter.attach(lcc)
// eslint-disable-next-line dot-notation
expect((lcc["_onRequest"] as sinon.SinonSpy).calledOnce).to.be.true
const spyArgs = spy.firstCall.args
expect(spyArgs[0]).to.deep.equal({ method: "window/showDocument" })
expect(spyArgs[1]).to.equal(ShowDocumentAdapter.showDocument)
})

it("onRequest connection is called", async () => {
it("onRequest connection is called", () => {
const connection = createSpyConnection()
const lcc = new LanguageClientConnection(connection)

Expand All @@ -39,7 +41,7 @@ describe("ShowDocumentAdapter", () => {
})
})
describe("can show documents", () => {
describe("shows the document inside Atom", async () => {
describe("shows the document inside Atom", () => {
const helloPath = join(dirname(__dirname), "fixtures", "hello.js")

async function canShowDocumentInAtom(params: ShowDocumentParams) {
Expand Down
4 changes: 2 additions & 2 deletions test/auto-languageclient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ describe("AutoLanguageClient", () => {
})

it("does not select documents in unsupported language", () => {
const editor = mockEditor("/path/to/somewhere", client.getGrammarScopes()[0] + "-dummy")
const editor = mockEditor("/path/to/somewhere", `${client.getGrammarScopes()[0]}-dummy`)
expect(client.shouldSyncForEditor(editor, "/path/to/somewhere")).equals(false)
})

it("does not select documents in unsupported language outside of project", () => {
const editor = mockEditor("/path/to/elsewhere/file", client.getGrammarScopes()[0] + "-dummy")
const editor = mockEditor("/path/to/elsewhere/file", `${client.getGrammarScopes()[0]}-dummy`)
expect(client.shouldSyncForEditor(editor, "/path/to/somewhere")).equals(false)
})
})
Expand Down
6 changes: 3 additions & 3 deletions test/convert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe("Convert", () => {
it("uses getath which returns a path to create the URI", () => {
const path = "/c/d/e/f/g/h/i/j.txt"
const identifier = Convert.editorToTextDocumentIdentifier(createFakeEditor(path))
expect(identifier.uri).equals("file://" + path)
expect(identifier.uri).equals(`file://${path}`)
})
})

Expand All @@ -142,7 +142,7 @@ describe("Convert", () => {
const editor = createFakeEditor(path, "abc\ndefgh\nijkl")
editor.setCursorBufferPosition(new Point(1, 2))
const params = Convert.editorToTextDocumentPositionParams(editor)
expect(params.textDocument.uri).equals("file://" + path)
expect(params.textDocument.uri).equals(`file://${path}`)
expect(params.position).deep.equals({ line: 1, character: 2 })
})

Expand All @@ -152,7 +152,7 @@ describe("Convert", () => {
const editor = createFakeEditor(path, "abcdef\nghijkl\nmnopq")
editor.setCursorBufferPosition(new Point(1, 1))
const params = Convert.editorToTextDocumentPositionParams(editor, specifiedPoint)
expect(params.textDocument.uri).equals("file://" + path)
expect(params.textDocument.uri).equals(`file://${path}`)
expect(params.position).deep.equals({ line: 911, character: 112 })
})
})
Expand Down
4 changes: 2 additions & 2 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("Utils", () => {
it("returns the exe path under bin folder by default", () => {
let expectedExe = join(process.cwd(), "bin", `${process.platform}-${process.arch}`, "serve-d")
if (process.platform === "win32") {
expectedExe = expectedExe + ".exe"
expectedExe = `${expectedExe}.exe`
}

const fsMock = sinon.mock(fs)
Expand All @@ -65,7 +65,7 @@ describe("Utils", () => {
const rootPath = join(__dirname, `${process.platform}-${process.arch}`)
let expectedExe = join(rootPath, "serve-d")
if (process.platform === "win32") {
expectedExe = expectedExe + ".exe"
expectedExe = `${expectedExe}.exe`
}

const fsMock = sinon.mock(fs)
Expand Down