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
18 changes: 8 additions & 10 deletions .github/workflows/master-pushed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6
with:
fetch-depth: 0
# Allow pushing to `master` branch which is protected
# See https://github.com/settings/tokens/1477019585
token: ${{ secrets.GIT_PUSH_TOKEN }}

- uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
registry-url: 'https://registry.npmjs.org'
- uses: pnpm/action-setup@v5

- run: pnpm install --frozen-lockfile --ignore-scripts

- run: npm ci --ignore-scripts
# Publish to https://www.npmjs.com/package/positioning-strategy
# See https://www.npmjs.com/settings/rebasecop/tokens
- run: pnpm config set "//registry.npmjs.org/:_authToken" ${{ secrets.NPM_PUBLISH_TOKEN }}

- run: npx auto-npm-version
- run: pnpm exec auto-npm-version
env:
# Allow creating a new entry in https://github.com/taskworld/positioning-strategy/releases
GITHUB_TOKEN: ${{ secrets.GIT_PUSH_TOKEN }}
# Allow publishing to https://www.npmjs.com/package/positioning-strategy
# See https://www.npmjs.com/settings/rebasecop/tokens
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
18 changes: 18 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "./node_modules/oxfmt/configuration_schema.json",
"arrowParens": "always",
"bracketSameLine": false,
"bracketSpacing": true,
"endOfLine": "lf",
"ignorePatterns": ["**/*.js", "**/*.map", "**/*.d.ts", "coverage"],
"insertFinalNewline": true,
"jsxSingleQuote": false,
"objectWrap": "preserve",
"printWidth": 100,
"quoteProps": "as-needed",
"semi": false,
"singleAttributePerLine": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5"
}
44 changes: 44 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["import", "typescript", "unicorn", "vitest"],
"env": {
"browser": true
},
"ignorePatterns": ["**/*.js", "**/*.map", "**/*.d.ts", "coverage"],
"categories": {
"correctness": "error",
"suspicious": "error"
},
"rules": {
"eslint/eqeqeq": "error",
"eslint/no-shadow": "off", // Too picky
"eslint/no-nested-ternary": "warn",
"eslint/no-unused-vars": "off", // Rely on TypeScript compiler instead

"import/no-named-as-default": "off", // Too picky
"import/no-unassigned-import": "off", // Does not recognize CSS imports

"jest/consistent-test-it": ["error", { "fn": "it" }],
"jest/no-alias-methods": "error",
"jest/no-conditional-in-test": "warn",
"jest/no-identical-title": "error",
"jest/padding-around-test-blocks": "error",
"jest/prefer-equality-matcher": "error",
"jest/prefer-hooks-in-order": "error",
"jest/prefer-to-contain": "error",
"jest/prefer-to-have-length": "error",
"jest/valid-title": "off", // Rely on https://oxc.rs/docs/guide/usage/linter/rules/vitest/prefer-describe-function-title

"typescript/no-base-to-string": "off", // Too picky
"typescript/no-floating-promises": "warn", // Too many errors
"typescript/no-explicit-any": "warn", // Too many errors
"typescript/no-unnecessary-type-assertion": "warn", // Too many errors
"typescript/no-unsafe-type-assertion": "warn", // Too many errors
"typescript/unbound-method": "off", // Too picky

"unicorn/explicit-length-check": "warn",
"unicorn/no-array-sort": "off", // Risk of backward-compatibility break

"vitest/prefer-describe-function-title": "warn"
}
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"editor.indentSize": 2,
"editor.defaultFormatter": "biomejs.biome"
"editor.defaultFormatter": "oxc.oxc-vscode",
"oxc.typeAware": true
}
37 changes: 0 additions & 37 deletions biome.jsonc

This file was deleted.

17 changes: 10 additions & 7 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const moveBy = (dx: number, dy: number) => (rect) => ({
describe('strategies', () => {
const testStrategy = (strategyName, expectedResult) => {
const menuRect = { width: 12, height: 6 }

it(`${strategyName}`, () => {
const args: Parameters<typeof calculateChildPosition> = [
strategyName,
Expand Down Expand Up @@ -192,13 +193,7 @@ describe('primary axis', () => {

it('bounces to the other direction on overflow', () => {
assertVisual(
[
'bottom left',
moveBy(0, 5)(buttonRect),
menuRect,
viewportRect,
{ gap: 1 },
],
['bottom left', moveBy(0, 5)(buttonRect), menuRect, viewportRect, { gap: 1 }],
// Despite the "bottom left" strategy,
// there is not enough space at the bottom.
// Therefore, the menu gets bounced to the top.
Expand Down Expand Up @@ -226,6 +221,7 @@ describe('primary axis', () => {
`
)
})

it('tries to keep menu fully on-screen', () => {
assertVisual(
['bottom left', buttonRect, menuRect, viewportRect, { gap: 1 }],
Expand Down Expand Up @@ -254,6 +250,7 @@ describe('primary axis', () => {
`
)
})

it('tries switching axis to minimize overlapping', () => {
const largerMenuRect = { width: 12, height: 12 }
assertVisual(
Expand Down Expand Up @@ -315,6 +312,7 @@ describe('secondary axis', () => {
`
)
})

it('aligns the right edge, when there is not enough space to the right', () => {
assertVisual(
['bottom', moveBy(30, 0)(buttonRect), menuRect, viewportRect],
Expand Down Expand Up @@ -342,6 +340,7 @@ describe('secondary axis', () => {
`
)
})

it('aligns the left edge, when there is not enough space to the left', () => {
assertVisual(
['bottom', moveBy(-30, 0)(buttonRect), menuRect, viewportRect],
Expand Down Expand Up @@ -369,6 +368,7 @@ describe('secondary axis', () => {
`
)
})

it('center-aligns if there is not enough space when right-aligned', () => {
assertVisual(
['bottom right', moveBy(-16, 0)(buttonRect), menuRect, viewportRect],
Expand Down Expand Up @@ -396,6 +396,7 @@ describe('secondary axis', () => {
`
)
})

it('center-aligns if there is not enough space when left-aligned', () => {
assertVisual(
['bottom left', moveBy(16, 0)(buttonRect), menuRect, viewportRect],
Expand Down Expand Up @@ -423,6 +424,7 @@ describe('secondary axis', () => {
`
)
})

it('left-aligns if there is not enough space when right-aligned and center-aligning would still cause an overflow', () => {
assertVisual(
['bottom right', moveBy(-24, 0)(buttonRect), menuRect, viewportRect],
Expand Down Expand Up @@ -450,6 +452,7 @@ describe('secondary axis', () => {
`
)
})

it('right-aligns if there is not enough space when left-aligned and center-aligning would still cause an overflow', () => {
assertVisual(
['bottom left', moveBy(24, 0)(buttonRect), menuRect, viewportRect],
Expand Down
15 changes: 9 additions & 6 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
commit-msg:
commands:
lint:
run: npm exec lint-commit-message {1}
run: pnpm exec lint-commit-message {1}
pre-commit:
parallel: true
commands:
prettier:
glob: "*.ts"
run: npm exec biome -- check --diagnostic-level=error --log-kind=compact --write {staged_files} && git add {staged_files}
lint:
glob: '*.ts'
run: pnpm run lint --fix --format=unix {staged_files}
stage_fixed: true
format:
run: pnpm exec oxfmt --no-error-on-unmatched-pattern {staged_files}
stage_fixed: true
test:
run: npm test -- --silent --reporter dot
run: pnpm run test --silent --reporter dot
Loading