Skip to content
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
7,463 changes: 4,731 additions & 2,732 deletions package-lock.json

Large diffs are not rendered by default.

53 changes: 26 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,38 +199,37 @@
}
},
"dependencies": {
"comment-json": "^4.2.4",
"comment-json": "^4.2.5",
"escape-string-regexp": "^5.0.0",
"json5": "github:adamhamlin/json5#v2.3.0",
"lodash": "^4.17.21",
"ts-pattern": "^5.2.0",
"yaml": "^2.5.0"
"radashi": "^12.6.0",
"ts-pattern": "^5.7.1",
"yaml": "^2.8.0"
},
"devDependencies": {
"@adamhamlin/eslint-config": "^1.4.1",
"@types/chai": "^4.3.17",
"@types/chai-as-promised": "^7.1.8",
"@types/chai": "^5.2.2",
"@types/chai-as-promised": "^8.0.2",
"@types/dedent": "^0.7.2",
"@types/glob": "^8.1.0",
"@types/lodash": "^4.17.7",
"@types/mocha": "^10.0.7",
"@types/node": "^22.x",
"@types/sinon": "^17.0.3",
"@types/sinon-chai": "^3.2.12",
"@types/vscode": "^1.74.0",
"@vscode/test-electron": "^2.4.1",
"@vscode/vsce": "^2.31.1",
"c8": "^10.1.2",
"chai": "^4.5.0",
"chai-as-promised": "^7.1.1",
"dedent": "^1.5.3",
"glob": "^8.0.3",
"glob-promise": "^6.0.7",
"husky": "^9.1.4",
"lint-staged": "^15.2.8",
"@types/lodash": "^4.17.20",
"@types/mocha": "^10.0.10",
"@types/node": "^24.x",
"@types/sinon": "^17.0.4",
"@types/sinon-chai": "^4.0.0",
"@types/vscode": "^1.102.0",
"@vscode/test-electron": "^2.5.2",
"@vscode/vsce": "^3.6.0",
"c8": "^10.1.3",
"chai": "^5.2.1",
"chai-as-promised": "^8.0.1",
"dedent": "^1.6.0",
"glob": "^11.0.3",
"husky": "^9.1.7",
"lint-staged": "^16.1.2",
"madge": "^8.0.0",
"mocha": "^10.7.0",
"sinon": "^18.0.0",
"sinon-chai": "^3.7.0",
"typescript": "^5.5.4"
"mocha": "^11.7.1",
"sinon": "^21.0.0",
"sinon-chai": "^4.0.0",
"typescript": "^5.8.3"
}
}
2 changes: 1 addition & 1 deletion src/commands/toggleBase64Encoding.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import vscode from 'vscode';

import { regexBasedBinaryToggle } from './shared/regexBasedBinaryToggle';
import { handleError } from '../utils';
import { regexBasedBinaryToggle } from './shared/regexBasedBinaryToggle';

export const TOGGLE_BASE64_ENCODING_CMD = 'toggleBase64Encoding';

Expand Down
5 changes: 2 additions & 3 deletions src/commands/toggleCase.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import _ from 'lodash';
import vscode from 'vscode';

import { regexBasedBinaryToggle } from './shared/regexBasedBinaryToggle';
import { getConfig } from '../configuration';
import { regexBasedBinaryToggle } from './shared/regexBasedBinaryToggle';
import { CASE_EXTRA_WORD_CHARS } from '../configuration/configuration.constants';
import { handleError } from '../utils';

Expand All @@ -22,5 +21,5 @@ export async function toggleCase(editor: vscode.TextEditor): Promise<void> {
}

function transform(originalText: string, hasLowercase: boolean): string {
return hasLowercase ? _.toUpper(originalText) : _.toLower(originalText);
return hasLowercase ? originalText.toUpperCase() : originalText.toLowerCase();
}
3 changes: 1 addition & 2 deletions src/commands/toggleJsonToJsToYaml.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import JSON5 from 'json5';
import _ from 'lodash';
import vscode from 'vscode';
import YAML from 'yaml';

Expand Down Expand Up @@ -102,7 +101,7 @@ abstract class SerializationFormatter {
this.looksLikeJsonObjectOrArray = [
['{', '}'],
['[', ']'],
].some(([open, close]) => _.startsWith(this.text, open) && _.endsWith(this.text, close));
].some(([open, close]) => this.text.startsWith(open) && this.text.endsWith(close));
this.indent = this.computeIndentation();
}

Expand Down
1 change: 0 additions & 1 deletion src/commands/toggleNewlineChars.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash';
import { match } from 'ts-pattern';
import vscode from 'vscode';

Expand Down
7 changes: 4 additions & 3 deletions src/commands/toggleQuotes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash';
import escapeStringRegexp from 'escape-string-regexp';
import _ from 'radashi';
import vscode from 'vscode';

import { getConfig } from '../configuration';
Expand Down Expand Up @@ -55,7 +56,7 @@ export async function toggleQuotes(editor: vscode.TextEditor): Promise<void> {
const quoteChars = getConfig<string[]>(QUOTE_CHARS);
const extraWordChars: string[] = []; // TODO: Make this configurable?
for (const char of quoteChars) {
if (_.escapeRegExp(char).length !== 1) {
if (escapeStringRegexp(char).length !== 1) {
throw new UserError(
'All configured quote characters must be strings of length 1 and cannot be special regex characters!'
);
Expand Down Expand Up @@ -165,7 +166,7 @@ function getQuotedStrings(
extraWordChars: string[]
): QuoteMatch[] {
// We need special handling for backticks, if configured
const standardQuoteChars = _.without(quoteChars, '`');
const standardQuoteChars = _.remove(quoteChars, (char) => char === '`');
const usingBackticks = standardQuoteChars.length < quoteChars.length;

let regexStr = QUOTE_REGEX_TEMPLATE.replace(QUOTE_CHARS_PLACEHOLDER, standardQuoteChars.join(''));
Expand Down
2 changes: 1 addition & 1 deletion src/commands/toggleUrlEncoding.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import vscode from 'vscode';

import { regexBasedBinaryToggle } from './shared/regexBasedBinaryToggle';
import { handleError } from '../utils';
import { regexBasedBinaryToggle } from './shared/regexBasedBinaryToggle';

export const TOGGLE_URL_ENCODING_CMD = 'toggleUrlEncoding';

Expand Down
11 changes: 7 additions & 4 deletions src/commands/toggleVariableNamingFormat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash';
import _ from 'radashi';
import vscode from 'vscode';

import { getConfig } from '../configuration';
Expand Down Expand Up @@ -70,7 +70,10 @@ export async function toggleVariableNamingFormat(editor: vscode.TextEditor): Pro
editor.document.getText(selectionsToToggle[0]),
namingFormatRegexMap
);
const targetFormat = getNextElement(_.keys(namingFormatRegexMap), currentFormat) as VariableNamingFormat;
const targetFormat = getNextElement(
Object.keys(namingFormatRegexMap),
currentFormat
) as VariableNamingFormat;

await editor.edit((builder) => {
for (const selection of selectionsToToggle) {
Expand All @@ -94,8 +97,8 @@ export async function toggleVariableNamingFormat(editor: vscode.TextEditor): Pro
* Get current variable naming format for the given text.
*/
function getCurrentNamingFormat(originalText: string, formatToRegexMap: NamingFormatRegexMap): VariableNamingFormat {
const formatList = _.keys(formatToRegexMap) as VariableNamingFormat[];
const currentFormat = _.find(formatList, (format) => {
const formatList = Object.keys(formatToRegexMap) as VariableNamingFormat[];
const currentFormat = formatList.find((format) => {
return formatToRegexMap[format].test(originalText);
});
if (!currentFormat) {
Expand Down
21 changes: 11 additions & 10 deletions src/configuration/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { basename } from 'path';

import _ from 'lodash';
// NOTE: Regexp.escape not available until ES2025
import escapeStringRegexp from 'escape-string-regexp';
import _ from 'radashi';
import vscode from 'vscode';

import { AUTO_FORMAT_ON_COMMENT_TOGGLE } from './configuration.constants';
import { EXTENSION_NAME } from '../constants';
import { getCurrentLang, parseJsonStripComments, UserError } from '../utils';
import { getCurrentLang, isObjectType, parseJsonStripComments, UserError } from '../utils';

type IndividualCommentConfig = {
line: string;
Expand Down Expand Up @@ -35,7 +37,7 @@ export function getConfig<T>(key: string, configurationName = EXTENSION_NAME): T
if (configValue === undefined) {
throw new UserError(`No value found for the configuration key ${key}.`);
}
return _.cloneDeep(configValue);
return isObjectType(configValue) ? _.cloneDeep(configValue) : configValue;
}

/**
Expand Down Expand Up @@ -66,10 +68,10 @@ export async function getCommentConfigForLanguage(): Promise<CommentConfig> {
blockEnd: isJavaScriptStyle ? ' */' : blockComment[1],
},
regex: {
line: _.escapeRegExp(commentConfig.lineComment),
blockStart: isJavaScriptStyle ? `${_.escapeRegExp('/**')}?` : _.escapeRegExp(blockComment[0]),
blockMiddle: isJavaScriptStyle ? `${_.escapeRegExp('*')}?` : '',
blockEnd: isJavaScriptStyle ? _.escapeRegExp('*/') : _.escapeRegExp(blockComment[1]),
line: escapeStringRegexp(commentConfig.lineComment),
blockStart: isJavaScriptStyle ? `${escapeStringRegexp('/**')}?` : escapeStringRegexp(blockComment[0]),
blockMiddle: isJavaScriptStyle ? `${escapeStringRegexp('*')}?` : '',
blockEnd: isJavaScriptStyle ? escapeStringRegexp('*/') : escapeStringRegexp(blockComment[1]),
},
};
languageToCommentConfigCache[language] = res;
Expand Down Expand Up @@ -97,9 +99,8 @@ export async function getLanguageConfigurationJson(
throw new Error(`Could not find extension '${languageExtensionName}'`);
}
const extensionUri = extension.extensionUri;
const configurationFilePath = _.find(
extension.packageJSON.contributes.languages,
(lang) => lang.id === language
const configurationFilePath = extension.packageJSON.contributes.languages.find(
(lang: { id: string }) => lang.id === language
)?.configuration;
if (!configurationFilePath) {
throw new Error(`Could not find a configuration file for ${language}`);
Expand Down
3 changes: 1 addition & 2 deletions src/models/comment/comment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash';
import vscode from 'vscode';

import { CommentConfig } from '../../configuration';
Expand All @@ -22,7 +21,7 @@ export class Comment {
private readonly config: CommentConfig,
indentationSize: number
) {
this.indentation = _.repeat(' ', indentationSize);
this.indentation = ' '.repeat(indentationSize);
}

getType(): CommentType {
Expand Down
1 change: 0 additions & 1 deletion src/models/comment/commentFinder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash';
import vscode from 'vscode';

import { Comment, CommentType } from './comment';
Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';

import glob from 'glob-promise';
import { glob } from 'glob';
import Mocha from 'mocha';

import { mochaHooks } from '../mocha.setup';
Expand Down
4 changes: 2 additions & 2 deletions src/test/suite/toggleBase64Encoding.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import dedent from 'dedent';
import _ from 'lodash';
import _ from 'radashi';
import vscode from 'vscode';

import { toggleBase64Encoding } from '../../commands/toggleBase64Encoding';
Expand Down Expand Up @@ -47,7 +47,7 @@ describe('toggleBase64Encoding cycles the base 64 encoding of a selection or wor
four?
`
);
for (const _iter of _.times(2)) {
for (const _iter of _.list(2)) {
await vscode.commands.executeCommand('editor.action.insertCursorBelow');
}
// All lines should be toggled to the same new quote character
Expand Down
4 changes: 2 additions & 2 deletions src/test/suite/toggleCase.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import dedent from 'dedent';
import _ from 'lodash';
import _ from 'radashi';
import vscode from 'vscode';

import { toggleCase } from '../../commands/toggleCase';
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('toggleCase cycles the case of a selection or word', () => {
sELECt * from CASE
`
);
for (const _iter of _.times(3)) {
for (const _iter of _.list(3)) {
await vscode.commands.executeCommand('editor.action.insertCursorBelow');
}
// All lines should be toggled to the same new quote character
Expand Down
8 changes: 4 additions & 4 deletions src/test/suite/toggleCommentType.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import dedent from 'dedent';
import _ from 'lodash';
import _ from 'radashi';
import sinon from 'sinon';
import vscode from 'vscode';

Expand Down Expand Up @@ -29,7 +29,7 @@ describe('toggleCommentType', () => {
sinon.restore();
});

_.forEach(testModes, (mode) => {
Object.values(testModes).forEach((mode) => {
describe(`cycles from line comment, to block, to free text, back to line comment -- ${mode}`, () => {
const errorMsg = 'Could not parse a valid comment encompassing the current line.';

Expand Down Expand Up @@ -605,11 +605,11 @@ describe('toggleCommentType', () => {
// NOTE: Limit is 150, so should be parsed as free text and go straight to line comment
const editor = await openEditorWithContentAndSelectAll(
'javascript',
['/**', _.times(151, (num) => ` * Line ${num}`).join('\n'), ' */'].join('\n')
['/**', _.list(0, 151, (num) => ` * Line ${num}`).join('\n'), ' */'].join('\n')
);
await toggleCommentTypeAndValidateText(
editor,
['// /**', _.times(151, (num) => `// * Line ${num}`).join('\n'), '// */'].join('\n')
['// /**', _.list(0, 151, (num) => `// * Line ${num}`).join('\n'), '// */'].join('\n')
);
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/suite/toggleJsonToJsToYaml.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import dedent from 'dedent';
import _ from 'lodash';
import _ from 'radashi';
import vscode from 'vscode';

import { toggleJsonToJsToYaml } from '../../commands/toggleJsonToJsToYaml';
Expand Down Expand Up @@ -420,7 +420,7 @@ describe('toggleJsonToJsToYaml cycles between strict JSON, Javascript, and YAML
{ b: 'B' }
`
);
for (const _iter of _.times(2)) {
for (const _iter of _.list(2)) {
await vscode.commands.executeCommand('editor.action.insertCursorBelow');
}
await expect(toggleJsonToJsToYaml(editor)).to.be.rejectedWith(usageError);
Expand Down
1 change: 0 additions & 1 deletion src/test/suite/toggleNewlineChars.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect } from 'chai';
import dedent from 'dedent';
import _ from 'lodash';
import vscode from 'vscode';

import { toggleNewlineChars } from '../../commands/toggleNewlineChars';
Expand Down
6 changes: 3 additions & 3 deletions src/test/suite/toggleQuotes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import dedent from 'dedent';
import _ from 'lodash';
import _ from 'radashi';
import vscode from 'vscode';

import { toggleQuotes } from '../../commands/toggleQuotes';
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('toggleQuotes cycles the quote characters used in a string or selection
"string 4"
`
);
for (const _iter of _.times(3)) {
for (const _iter of _.list(3)) {
await vscode.commands.executeCommand('editor.action.insertCursorBelow');
}
// All lines should be toggled to the same new quote character
Expand Down Expand Up @@ -148,7 +148,7 @@ describe('toggleQuotes cycles the quote characters used in a string or selection
\`string3\`
`
);
for (const _iter of _.times(4)) {
for (const _iter of _.list(4)) {
await vscode.commands.executeCommand('editor.action.insertCursorBelow');
}
// All lines should be toggled to the same new quote character
Expand Down
4 changes: 2 additions & 2 deletions src/test/suite/toggleUrlEncoding.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import dedent from 'dedent';
import _ from 'lodash';
import _ from 'radashi';
import vscode from 'vscode';

import { toggleUrlEncoding } from '../../commands/toggleUrlEncoding';
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('toggleUrlEncoding cycles the URL encoding of a selection or word', ()
encode?
`
);
for (const _iter of _.times(2)) {
for (const _iter of _.list(2)) {
await vscode.commands.executeCommand('editor.action.insertCursorBelow');
}
// All lines should be toggled to the same new quote character
Expand Down
Loading
Loading