Skip to content

Commit

Permalink
Merge pull request #22 from HiDeoo/hd-fix-update
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo authored Nov 13, 2023
2 parents 4b3dcdb + 5d36f78 commit 3455544
Show file tree
Hide file tree
Showing 19 changed files with 3,147 additions and 2,112 deletions.
22 changes: 1 addition & 21 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"extends": ["plugin:prettier/recommended"],
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/class-name-casing": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off",
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
]
}
"extends": ["@hideoo"]
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
24 changes: 18 additions & 6 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
name: integration

on: [push, pull_request]
on:
push:
branches:
- '**'
tags-ignore:
- '**'
pull_request:

concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }}

jobs:
test:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '12'
node-version: 18
cache: 'yarn'

- name: Install dependencies
run: yarn
Expand All @@ -27,11 +39,11 @@ jobs:
run: yarn lint

- name: Test extension
uses: GabrielBB/xvfb-action@v1.0
uses: coactions/setup-xvfb@v1
with:
run: yarn test:desktop

- name: Test web extension
uses: GabrielBB/xvfb-action@v1.0
uses: coactions/setup-xvfb@v1
with:
run: yarn test:web
37 changes: 32 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
out
.astro
.DS_Store
.eslintcache
.idea
.next
.turbo
.vercel
.vscode/*
!.vscode/extensions.json
!.vscode/launch.json
!.vscode/settings.json
!.vscode/tasks.json
.vscode-test
.vscode-test-web
*.local
*.log
*.pem
*.tsbuildinfo
build
coverage
dist
dist-ssr
lerna-debug.log*
logs
next-env.d.ts
node_modules
.vscode-test/
.vscode-test-web/
*.vsix
.DS_Store
npm-debug.log*
out
pnpm-debug.log*
releases
toggler-**.vsix
test-results
yarn-debug.log*
yarn-error.log*
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx ynpx lint-staged
13 changes: 12 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
package.json
.astro
.github/blocks
.next
.vercel
.vscode
.vscode-test
.vscode-test-web
build
coverage
dist
dist-ssr
out
pnpm-lock.yaml
7 changes: 0 additions & 7 deletions .prettierrc

This file was deleted.

3 changes: 3 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ node_modules/**
**/*.ts
.github/**
.prettierignore
.eslintcache
.husky/**
tsconfig.tsbuildinfo
56 changes: 26 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,46 +134,42 @@
"watch:test": "tsc --watch -p .",
"preweb": "yarn build",
"web": "vscode-test-web --extensionDevelopmentPath=. --browserType=chromium",
"lint": "eslint src --ext ts",
"lint": "prettier -c --cache . && eslint . --cache --max-warnings=0 && tsc --noEmit",
"pretest": "yarn build && yarn build:test",
"test": "yarn test:desktop && yarn test:web",
"test:desktop": "node out/test/runTest.js",
"test:web": "yarn web --extensionTestsPath=dist/test/suite/index.js --headless=true",
"package": "webpack --mode production --devtool hidden-source-map",
"vscode:package": "npx vsce package",
"vscode:prepublish": "yarn package"
"vscode:package": "npx @vscode/vsce package",
"vscode:prepublish": "yarn package",
"prepare": "husky install"
},
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/mocha": "^7.0.2",
"@types/node": "^13.11.0",
"@hideoo/eslint-config": "2.0.2",
"@hideoo/prettier-config": "2.0.0",
"@hideoo/tsconfig": "2.0.1",
"@types/mocha": "10.0.4",
"@types/node": "18.18.9",
"@types/vscode": "1.42.0",
"@types/webpack-env": "1.16.2",
"@typescript-eslint/eslint-plugin": "^2.30.0",
"@typescript-eslint/parser": "^2.30.0",
"@vscode/test-web": "0.0.22",
"assert": "2.0.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "6.11.0",
"eslint-plugin-prettier": "3.1.3",
"glob": "^7.1.6",
"husky": ">=4",
"lint-staged": ">=10",
"mocha": "^7.1.2",
"prettier": "2.0.5",
"@types/webpack-env": "1.18.4",
"@vscode/test-electron": "2.3.6",
"@vscode/test-web": "0.0.48",
"assert": "2.1.0",
"eslint": "8.53.0",
"glob": "10.3.10",
"husky": "8.0.3",
"lint-staged": "15.1.0",
"mocha": "10.2.0",
"prettier": "3.1.0",
"process": "0.11.10",
"ts-loader": "9.2.5",
"typescript": "^3.8.3",
"vscode-test": "^1.3.0",
"webpack": "5.51.2",
"webpack-cli": "4.8.0"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
"ts-loader": "9.5.0",
"typescript": "5.2.2",
"webpack": "5.89.0",
"webpack-cli": "5.1.4"
},
"prettier": "@hideoo/prettier-config",
"lint-staged": {
"*.{ts,md}": "prettier --write"
"**/*": "prettier -w -u --cache",
"**/*.{js,jsx,ts,tsx,cjs,mjs}": "eslint --cache --max-warnings=0"
}
}
42 changes: 25 additions & 17 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { commands, ExtensionContext, Range, Selection, TextEditor, window, workspace } from 'vscode'
import { commands, type ExtensionContext, Range, type Selection, type TextEditor, window, workspace } from 'vscode'

import * as defaults from './defaults.json'
import defaults from './defaults.json'

/**
* Toggler command identifiers.
Expand All @@ -13,7 +13,7 @@ export const TogglerCommands = {
/**
* RegExp special characters.
*/
const RegExpCharacters = /[|\\{}()[\]^$+*?.]/g
const RegExpCharacters = /[$()*+.?[\\\]^{|}]/g

/**
* Toggler configuration.
Expand Down Expand Up @@ -42,7 +42,7 @@ export function activate(context: ExtensionContext) {
if (event.affectsConfiguration('toggler')) {
resetConfiguration()
}
})
}),
)
}

Expand Down Expand Up @@ -70,7 +70,7 @@ function loadConfiguration() {

const languageId = window.activeTextEditor.document.languageId

if (configuration && configuration[languageId]) {
if (configuration?.[languageId]) {
return
}

Expand All @@ -80,7 +80,7 @@ function loadConfiguration() {

let customToggles: ToggleConfiguration[] = []

const togglerConfiguration = workspace.getConfiguration('toggler', window.activeTextEditor?.document)
const togglerConfiguration = workspace.getConfiguration('toggler', window.activeTextEditor.document)

const useDefaultToggles = togglerConfiguration.get<boolean>('useDefaultToggles', true)
const customTogglesInfos = togglerConfiguration.inspect<ToggleConfiguration[]>('toggles')
Expand All @@ -93,14 +93,14 @@ function loadConfiguration() {
}
}

configuration[languageId] = useDefaultToggles ? customToggles.concat(defaults) : customToggles
configuration[languageId] = useDefaultToggles ? [...customToggles, ...defaults] : customToggles
}

/**
* Opens the Toggler settings.
*/
function openTogglerSettings() {
commands.executeCommand('workbench.action.openSettings', '@ext:hideoo.toggler')
void commands.executeCommand('workbench.action.openSettings', '@ext:hideoo.toggler')
}

/**
Expand All @@ -118,7 +118,7 @@ function toggle() {
return editor.edit(async (editBuilder) => {
let didFail = false

selections.forEach((selection) => {
for (const selection of selections) {
const toggle = getToggle(editor, selection)

if (toggle.new) {
Expand All @@ -132,7 +132,7 @@ function toggle() {
} else {
didFail = true
}
})
}

if (didFail) {
const togglerConfiguration = workspace.getConfiguration('toggler', window.activeTextEditor?.document)
Expand All @@ -146,7 +146,7 @@ function toggle() {

const result = await window.showWarningMessage(
`Toggler: Could not find a toggle. You can add one in your VS Code settings.`,
settingsButton
settingsButton,
)

if (result === settingsButton) {
Expand All @@ -173,7 +173,7 @@ function getToggle(editor: TextEditor, selection: Selection): Toggle {
selected,
}

if (!configuration || !configuration[editor.document.languageId]) {
if (!configuration?.[editor.document.languageId]) {
return toggle
}

Expand All @@ -183,11 +183,14 @@ function getToggle(editor: TextEditor, selection: Selection): Toggle {
lineText = editor.document.lineAt(cursorPosition).text
}

for (let i = 0; i < languageConfiguration.length; i++) {
const words = languageConfiguration[i]

for (const words of languageConfiguration ?? []) {
for (let j = 0; j < words.length; j++) {
const currentWord = words[j]

if (!currentWord) {
continue
}

const nextWordIndex = (j + 1) % words.length

if (!selected && lineText) {
Expand All @@ -212,6 +215,11 @@ function getToggle(editor: TextEditor, selection: Selection): Toggle {

if (word.toLowerCase() === lowerCaseCurrentWord) {
const nextWord = words[nextWordIndex]

if (!nextWord) {
return toggle
}

const nextWordHasUppercase = /[A-Z]/.test(nextWord)

if (!nextWordHasUppercase && word === lowerCaseCurrentWord) {
Expand Down Expand Up @@ -248,7 +256,7 @@ function capitalize(aString: string) {
* @see https://github.com/sindresorhus/escape-string-regexp
*/
function escapeStringRegExp(aString: string) {
return aString.replace(RegExpCharacters, '\\$&')
return aString.replaceAll(RegExpCharacters, '\\$&')
}

/**
Expand All @@ -259,7 +267,7 @@ type ToggleConfiguration = string[]
/**
* Toggle operation result.
*/
type Toggle = {
interface Toggle {
// Defines if the toggle is based on a user selection or guessed on a cursor position.
selected: boolean
// Range of the toggled words when the toggle is based on a cursor position.
Expand Down
6 changes: 3 additions & 3 deletions src/test/mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export function runTests(mocha: Mocha | BrowserMocha, resolve: () => void, rejec
resolve()
}
})
} catch (err) {
console.error(err)
reject(err)
} catch (error) {
console.error(error)
reject(error)
}
}

Expand Down
Loading

0 comments on commit 3455544

Please sign in to comment.