Skip to content

Commit

Permalink
Update code style for repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
71 committed Mar 19, 2021
1 parent 047e203 commit 1b3e222
Show file tree
Hide file tree
Showing 32 changed files with 933 additions and 819 deletions.
13 changes: 10 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ module.exports = {
},
],
rules: {
"indent": ["error", 2, {
"VariableDeclarator": "first",
"flatTernaryExpressions": true,
"offsetTernaryExpressions": true,
}],
"curly": ["error", "all"],
"dot-location": ["error", "property"],
"eqeqeq": ["error", "always", { null: "ignore" }],
Expand All @@ -31,16 +36,18 @@ module.exports = {
"max-len": [
"warn",
{
code: 200,
comments: 120,
ignorePattern: "^ +(\\*|\\/\\/) http\\S+\\)?.?$",
code: 100,
comments: 80,
ignorePattern: "^ *(\\*|//) ([sS]ee )?http\\S+\\)?.?$|^ *// =+( [^=]+ =+)?$",
},
],
"multiline-ternary": ["error", "always-multiline"],
"no-tabs": "error",
"no-trailing-spaces": "error",
"no-unexpected-multiline": "error",
"no-unneeded-ternary": "error",
"object-curly-spacing": ["error", "always"],
"operator-linebreak": ["error", "before"],
"object-shorthand": "error",
"quotes": ["error", "double", { avoidEscape: true, allowTemplateLiterals: true }],
"semi": ["error", "always"],
Expand Down
5 changes: 0 additions & 5 deletions .prettierignore

This file was deleted.

12 changes: 0 additions & 12 deletions .prettierrc.js

This file was deleted.

9 changes: 5 additions & 4 deletions commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ for (const id in yaml) {
)
.join(", ");

const docStringKeys =
docKeys.length === 0 ? "" : `\n *\n * Default key${keys.length === 1 ? "" : "s"}: ${docKeys}.`;
const docStringKeys = docKeys.length === 0
? ""
: `\n *\n * Default key${keys.length === 1 ? "" : "s"}: ${docKeys}.`;

const docCommandName = command.command ? "" : `\`${prefix}.${id}\``;
doc.write(`| ${docCommandName} | ${command.title} | ${command.descr} | ${docKeys} |\n`);
Expand Down Expand Up @@ -250,8 +251,8 @@ ${commands.map((x) => ` /** ${yaml[x].descr} */\n ${writable(x)}`).join(",\n")
*/
export const enum Command {
${commands
.map((x) => ` /** ${yaml[x].descr} */\n ${writable(x)} = "${prefix}.${x}"`)
.join(",\n")},
.map((x) => ` /** ${yaml[x].descr} */\n ${writable(x)} = "${prefix}.${x}"`)
.join(",\n")},
}
/**
Expand Down
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"vscode": "^1.44.0"
},
"scripts": {
"check": "prettier --check . && eslint .",
"format": "prettier --write .",
"check": "eslint .",
"format": "eslint . --fix",
"generate": "ts-node ./commands/generate.ts && ts-node package.ts",
"vscode:prepublish": "yarn run generate && yarn run compile",
"compile": "tsc -p ./",
Expand All @@ -38,19 +38,17 @@
"@types/js-yaml": "^3.12.3",
"@types/mocha": "^8.0.3",
"@types/node": "^14.6.0",
"@types/prettier": "^2.1.2",
"@types/vscode": "^1.44.0",
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/parser": "^4.4.1",
"eslint": "^7.11.0",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"eslint": "^7.22.0",
"glob": "^7.1.6",
"js-yaml": "^3.13.0",
"mocha": "^8.1.1",
"prettier": "^2.1.2",
"source-map-support": "^0.5.19",
"ts-node": "^8.9.1",
"typescript": "^4.0.2",
"vsce": "^1.75.0",
"ts-node": "^9.1.1",
"typescript": "^4.2.3",
"vsce": "^1.87.0",
"vscode-test": "^1.3.0"
},
"activationEvents": [
Expand Down
38 changes: 20 additions & 18 deletions package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const keybindings: {
}[] = additionalKeyBindings.concat();

const alphanum = [..."abcdefghijklmnopqrstuvwxyz0123456789"],
keysToAssign = new Set([...alphanum, ...alphanum.map((x) => `Shift+${x}`), ...",'"]);
keysToAssign = new Set([...alphanum, ...alphanum.map((x) => `Shift+${x}`), ...",'"]);

for (const command of Object.values(commands)) {
for (const { key, when } of command.keybindings) {
Expand Down Expand Up @@ -210,8 +210,8 @@ const pkg = {
},

scripts: {
"check": "prettier --check . && eslint .",
"format": "prettier --write .",
"check": "eslint .",
"format": "eslint . --fix",
"generate": "ts-node ./commands/generate.ts && ts-node package.ts",
"vscode:prepublish": "yarn run generate && yarn run compile",
"compile": "tsc -p ./",
Expand All @@ -226,19 +226,17 @@ const pkg = {
"@types/js-yaml": "^3.12.3",
"@types/mocha": "^8.0.3",
"@types/node": "^14.6.0",
"@types/prettier": "^2.1.2",
"@types/vscode": "^1.44.0",
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/parser": "^4.4.1",
"eslint": "^7.11.0",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"eslint": "^7.22.0",
"glob": "^7.1.6",
"js-yaml": "^3.13.0",
"mocha": "^8.1.1",
"prettier": "^2.1.2",
"source-map-support": "^0.5.19",
"ts-node": "^8.9.1",
"typescript": "^4.0.2",
"vsce": "^1.75.0",
"ts-node": "^9.1.1",
"typescript": "^4.2.3",
"vsce": "^1.87.0",
"vscode-test": "^1.3.0",
},

Expand All @@ -257,15 +255,17 @@ const pkg = {
type: ["string", "null"],
default: "editor.hoverHighlightBackground",
markdownDescription:
"Controls the line highlighting applied to active lines in normal mode. " +
"Can be an hex color, a [theme color](https://code.visualstudio.com/api/references/theme-color) or null.",
"Controls the line highlighting applied to active lines in normal mode. "
+ "Can be an hex color, a [theme color]("
+ "https://code.visualstudio.com/api/references/theme-color) or null.",
},
"dance.insertMode.lineHighlight": {
type: ["string", "null"],
default: null,
markdownDescription:
"Controls the line highlighting applied to active lines in insert mode. " +
"Can be an hex color, a [theme color](https://code.visualstudio.com/api/references/theme-color) or null.",
"Controls the line highlighting applied to active lines in insert mode. "
+ "Can be an hex color, a [theme color]("
+ "https://code.visualstudio.com/api/references/theme-color) or null.",
},
"dance.normalMode.lineNumbers": {
enum: ["off", "on", "relative", "inherit"],
Expand Down Expand Up @@ -339,9 +339,11 @@ const pkg = {
default: "caret",
description: "Controls how selections behave within VS Code.",
markdownEnumDescriptions: [
"Selections are anchored to carets, which is the native VS Code behavior; that is, they are positioned *between* characters and can therefore be empty.",
"Selections are anchored to characters, like Kakoune; that is, they are positioned *on* characters, and therefore cannot be empty. " +
"Additionally, one-character selections will behave as if they were non-directional, like Kakoune.",
"Selections are anchored to carets, which is the native VS Code behavior; that is, "
+ "they are positioned *between* characters and can therefore be empty.",
"Selections are anchored to characters, like Kakoune; that is, they are positioned "
+ "*on* characters, and therefore cannot be empty. Additionally, one-character "
+ "selections will behave as if they were non-directional, like Kakoune.",
],
},
"dance.menus": {
Expand Down
42 changes: 22 additions & 20 deletions src/commands/changes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Changes: https://github.com/mawww/kakoune/blob/master/doc/pages/keys.asciidoc#changes
// Changes
// https://github.com/mawww/kakoune/blob/master/doc/pages/keys.asciidoc#changes
import * as vscode from "vscode";

import { Command, CommandFlags, registerCommand } from ".";
Expand All @@ -13,28 +14,28 @@ registerCommand(
({ editor }, _, undoStops) => {
// Select all line endings.
const selections = editor.selections,
len = selections.length,
newSelections = [] as vscode.Selection[],
document = editor.document;
len = selections.length,
newSelections = [] as vscode.Selection[],
document = editor.document;

for (let i = 0; i < len; i++) {
const selection = selections[i],
startLine = selection.start.line,
endLine = selection.end.line,
startAnchor = new vscode.Position(startLine, Number.MAX_SAFE_INTEGER),
startActive = new vscode.Position(
startLine + 1,
document.lineAt(startLine + 1).firstNonWhitespaceCharacterIndex,
);
startLine = selection.start.line,
endLine = selection.end.line,
startAnchor = new vscode.Position(startLine, Number.MAX_SAFE_INTEGER),
startActive = new vscode.Position(
startLine + 1,
document.lineAt(startLine + 1).firstNonWhitespaceCharacterIndex,
);

newSelections.push(new vscode.Selection(startAnchor, startActive));

for (let line = startLine + 1; line < endLine; line++) {
const anchor = new vscode.Position(line, Number.MAX_SAFE_INTEGER),
active = new vscode.Position(
line + 1,
document.lineAt(line + 1).firstNonWhitespaceCharacterIndex,
);
active = new vscode.Position(
line + 1,
document.lineAt(line + 1).firstNonWhitespaceCharacterIndex,
);

newSelections.push(new vscode.Selection(anchor, active));
}
Expand Down Expand Up @@ -92,8 +93,9 @@ function getSelectionsLines(selections: vscode.Selection[]) {
function indent(editor: vscode.TextEditor, ignoreEmpty: boolean) {
return editor
.edit((builder) => {
const indent =
editor.options.insertSpaces === true ? " ".repeat(editor.options.tabSize as number) : "\t";
const indent = editor.options.insertSpaces === true
? " ".repeat(editor.options.tabSize as number)
: "\t";

for (const i of getSelectionsLines(editor.selections)) {
if (ignoreEmpty && editor.document.lineAt(i).isEmptyOrWhitespace) {
Expand All @@ -120,10 +122,10 @@ function deindent(editor: vscode.TextEditor, repetitions: number, further: boole

for (const i of getSelectionsLines(editor.selections)) {
const line = doc.lineAt(i),
text = line.text;
text = line.text;

let column = 0, // Column, accounting for tab size
j = 0; // Index in source line, and number of characters to remove
j = 0; // Index in source line, and number of characters to remove

for (; column < needed; j++) {
const char = text[j];
Expand Down Expand Up @@ -191,7 +193,7 @@ registerCommand(Command.swapCase, CommandFlags.Edit, ({ editor }) =>

for (let i = 0; i < text.length; i++) {
const x = text[i],
loCase = x.toLocaleLowerCase();
loCase = x.toLocaleLowerCase();

builtText += loCase === x ? x.toLocaleUpperCase() : loCase;
}
Expand Down
10 changes: 5 additions & 5 deletions src/commands/goto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ registerCommand(
(editorState, state) => {
if (state.input === null) {
const { editor } = editorState,
{ document } = editor;
{ document } = editor;
let line = state.currentCount - 1;

if (line >= document.lineCount) {
line = document.lineCount - 1;
}

const active = new vscode.Position(line, 0),
anchor = new vscode.Position(line, 0);
anchor = new vscode.Position(line, 0);

editor.selections = [new vscode.Selection(anchor, active)];

Expand All @@ -72,15 +72,15 @@ registerCommand(
(editorState, state) => {
if (state.input === null) {
const { editor } = editorState,
{ document, selection } = editor;
{ document, selection } = editor;
let line = state.currentCount - 1;

if (line >= document.lineCount) {
line = document.lineCount - 1;
}

const anchor = selection.anchor,
active = new vscode.Position(line, 0);
active = new vscode.Position(line, 0);

editor.selections = [new vscode.Selection(anchor, active)];

Expand Down Expand Up @@ -284,7 +284,7 @@ function toLastBufferModification(editorState: EditorState, extend: ExtendBehavi

if (documentState.recordedChanges.length > 0) {
const range = documentState.recordedChanges[documentState.recordedChanges.length - 1].range,
selection = range.selection(documentState.document);
selection = range.selection(documentState.document);

editor.selection = extend
? new vscode.Selection(editor.selection.anchor, selection.active)
Expand Down
4 changes: 2 additions & 2 deletions src/commands/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ registerCommand(
const commandState = commands[i];

if (
commandState.descriptor.flags & CommandFlags.ChangeSelections &&
!(commandState.descriptor.flags & CommandFlags.Edit)
commandState.descriptor.flags & CommandFlags.ChangeSelections
&& !(commandState.descriptor.flags & CommandFlags.Edit)
) {
return CommandDescriptor.execute(editorState, commandState);
}
Expand Down
Loading

0 comments on commit 1b3e222

Please sign in to comment.