Skip to content

Commit

Permalink
switch to pre-commit-based linting
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswilm committed Nov 23, 2024
1 parent e04318b commit 78b3cfe
Show file tree
Hide file tree
Showing 29 changed files with 1,962 additions and 1,450 deletions.
29 changes: 19 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,33 @@ on:
- develop

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

workflow_dispatch: {}
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install dependencies
run: |
pip install pip --upgrade
if grep version pyproject.toml | grep -q "dev";
then pip install https://github.com/fiduswriter/fiduswriter/archive/develop.zip;
else pip install https://github.com/fiduswriter/fiduswriter/archive/main.zip;
fi
- uses: pre-commit/action@v3
test:
name: Run tests
runs-on: ubuntu-latest

steps:
- name: Check out Git repository
uses: actions/checkout@v4.1.2
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5.1.0
uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: "3.13"
- name: Set up Node
uses: actions/setup-node@v4
with:
Expand All @@ -49,10 +62,6 @@ jobs:
pip install flake8
pip install black
coverage run $(which fiduswriter) setup --no-static
- name: Run linters
run: |
cd fiduswriter
fiduswriter lint
- name: Run tests
uses: nick-invision/retry@v3
with:
Expand Down
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.10.0
hooks:
- id: black
args: [--line-length=79]
language_version: python3.13
- repo: https://github.com/pycqa/flake8
rev: '7.1.1'
hooks:
- id: flake8
entry: flake8 --extend-ignore E203,E501
- repo: https://github.com/biomejs/pre-commit
rev: "75149f4e3b63c4df805860d7b04186d56dcbc05c"
hooks:
- id: biome-check
#entry: biome check --files-ignore-unknown=true --no-errors-on-unmatched --fix --unsafe
additional_dependencies: ["@biomejs/[email protected]"]
- repo: https://github.com/awebdeveloper/pre-commit-stylelint
rev: "4200758f4cb2f53dd06898dd8dca35e4b8cfb785"
hooks:
- id: stylelint
additional_dependencies:
[
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
]
- repo: local
hooks:
- id: django-import-resolver
name: Django Import Resolver
entry: node lint/django_import_resolver.js
language: node
files: \.js$
additional_dependencies: ["[email protected]"]
170 changes: 170 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
"formatter": {
"enabled": true,
"useEditorconfig": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 4,
"lineEnding": "lf",
"lineWidth": 80,
"attributePosition": "auto",
"bracketSpacing": true,
"ignore": [
"**/.transpile-cache/",
"**/venv/",
"**/static-transpile/",
"**/static-libs/",
"**/static-collected/",
"**/node-modules/",
"**/testing/",
"**/.eslintrc.mjs",
"**/*.json",
"**/*.html",
"**/.direnv",
"**/venv",
"**/.transpile",
"**/.babelrc",
"**/sw-template.js"
]
},
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"complexity": {
"noExtraBooleanCast": "error",
"noMultipleSpacesInRegularExpressionLiterals": "error",
"noUselessCatch": "off",
"noUselessConstructor": "off",
"noUselessLabel": "error",
"noUselessLoneBlockStatements": "error",
"noUselessRename": "error",
"noUselessStringConcat": "error",
"noUselessTernary": "off",
"noUselessUndefinedInitialization": "error",
"noVoid": "error",
"noWith": "error",
"useLiteralKeys": "off"
},
"correctness": {
"noConstAssign": "error",
"noConstantCondition": "error",
"noEmptyCharacterClassInRegex": "error",
"noEmptyPattern": "error",
"noGlobalObjectCalls": "error",
"noInnerDeclarations": "error",
"noInvalidConstructorSuper": "error",
"noInvalidUseBeforeDeclaration": "off",
"noNewSymbol": "error",
"noNonoctalDecimalEscape": "error",
"noPrecisionLoss": "error",
"noSelfAssign": "error",
"noSetterReturn": "error",
"noSwitchDeclarations": "error",
"noUndeclaredVariables": "error",
"noUnreachable": "error",
"noUnreachableSuper": "error",
"noUnsafeFinally": "error",
"noUnsafeOptionalChaining": "error",
"noUnusedLabels": "error",
"noUnusedVariables": "error",
"useArrayLiterals": "error",
"useIsNan": "error",
"useValidForDirection": "error",
"useYield": "error"
},
"security": { "noGlobalEval": "error" },
"style": {
"noArguments": "off",
"noCommaOperator": "error",
"noNegationElse": "off",
"noParameterAssign": "off",
"noRestrictedGlobals": { "level": "error", "options": {} },
"noVar": "error",
"noYodaExpression": "off",
"useBlockStatements": "error",
"useCollapsedElseIf": "off",
"useConsistentBuiltinInstantiation": "error",
"useConst": "warn",
"useDefaultSwitchClause": "off",
"useNumericLiterals": "error",
"useShorthandAssign": "off",
"useSingleVarDeclarator": "off",
"useTemplate": "off"
},
"suspicious": {
"noAsyncPromiseExecutor": "error",
"noCatchAssign": "error",
"noClassAssign": "error",
"noCompareNegZero": "error",
"noControlCharactersInRegex": "off",
"noDebugger": "error",
"noDoubleEquals": "off",
"noDuplicateCase": "error",
"noDuplicateClassMembers": "error",
"noDuplicateObjectKeys": "error",
"noDuplicateParameters": "error",
"noEmptyBlockStatements": "off",
"noFallthroughSwitchClause": "error",
"noFunctionAssign": "error",
"noGlobalAssign": "error",
"noImportAssign": "error",
"noLabelVar": "error",
"noMisleadingCharacterClass": "error",
"noPrototypeBuiltins": "off",
"noRedeclare": "error",
"noSelfCompare": "error",
"noShadowRestrictedNames": "error",
"noSparseArray": "error",
"noUnsafeNegation": "error",
"useAwait": "error",
"useGetterReturn": "error",
"useValidTypeof": "error"
}
},
"ignore": [
"**/.transpile-cache/",
"**/venv/",
"**/static-transpile/",
"**/static-libs/",
"**/static-collected/",
"**/testing/",
"**/manifest.json",
"**/sw-template.js"
]
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "none",
"semicolons": "asNeeded",
"indentWidth": 4,
"arrowParentheses": "asNeeded",
"bracketSameLine": true,
"quoteStyle": "double",
"attributePosition": "auto",
"bracketSpacing": false
},
"globals": [
"settings_MEDIA_MAX_SIZE",
"settings_SOCIALACCOUNT_OPEN",
"settings_REGISTRATION_OPEN",
"gettext",
"interpolate",
"settings_USE_SERVICE_WORKER",
"transpile_VERSION",
"settings_TEST_SERVER",
"settings_DEBUG",
"settings_SOURCE_MAPS",
"settings_STATIC_URL",
"settings_PASSWORD_LOGIN",
"process",
"staticUrl",
"settings_CONTACT_EMAIL",
"settings_IS_FREE",
"settings_FOOTER_LINKS",
"settings_BRANDING_LOGO"
]
}
}
2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pre-commit==4.0.1
fiduswriter
522 changes: 261 additions & 261 deletions fiduswriter/book/fixtures/initial_book_data.json

Large diffs are not rendered by default.

85 changes: 43 additions & 42 deletions fiduswriter/book/static/js/modules/books/accessrights/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class BookAccessRightsDialog {
.forEach(el => {
accessRights.push({
holder: {
id: parseInt(el.dataset.id),
id: Number.parseInt(el.dataset.id),
type: el.dataset.type
},
rights: el.dataset.rights
Expand Down Expand Up @@ -182,7 +182,8 @@ export class BookAccessRightsDialog {
const collaborator = this.contacts.find(
contact =>
contact.type === el.dataset.type &&
contact.id === parseInt(el.dataset.id)
contact.id ===
Number.parseInt(el.dataset.id)
)
if (!collaborator) {
console.warn(
Expand Down Expand Up @@ -218,47 +219,47 @@ export class BookAccessRightsDialog {
this.dialog.dialogEl.addEventListener("click", event => {
const el = {}
switch (true) {
case findTarget(event, ".fw-checkable", el):
setCheckableLabel(el.target)
break
case findTarget(event, ".edit-right", el): {
const colRow = el.target.closest(
".collaborator-tr,.invite-tr"
)
const currentRight = colRow.dataset.rights
const menu = this.getDropdownMenu(
currentRight,
newRight => {
colRow.dataset.rights = newRight
colRow
.querySelector(".icon-access-right")
.setAttribute(
"class",
`icon-access-right icon-access-${newRight}`
)
}
)
const contentMenu = new ContentMenu({
menu,
menuPos: {X: event.pageX, Y: event.pageY},
width: 200
})
contentMenu.open()
break
}
case findTarget(event, ".delete-collaborator", el): {
const colRow = el.target.closest(".collaborator-tr")
colRow.dataset.right = "delete"
colRow
.querySelector(".icon-access-right")
.setAttribute(
"class",
"icon-access-right icon-access-delete"
case findTarget(event, ".fw-checkable", el):
setCheckableLabel(el.target)
break
case findTarget(event, ".edit-right", el): {
const colRow = el.target.closest(
".collaborator-tr,.invite-tr"
)
break
}
default:
break
const currentRight = colRow.dataset.rights
const menu = this.getDropdownMenu(
currentRight,
newRight => {
colRow.dataset.rights = newRight
colRow
.querySelector(".icon-access-right")
.setAttribute(
"class",
`icon-access-right icon-access-${newRight}`
)
}
)
const contentMenu = new ContentMenu({
menu,
menuPos: {X: event.pageX, Y: event.pageY},
width: 200
})
contentMenu.open()
break
}
case findTarget(event, ".delete-collaborator", el): {
const colRow = el.target.closest(".collaborator-tr")
colRow.dataset.right = "delete"
colRow
.querySelector(".icon-access-right")
.setAttribute(
"class",
"icon-access-right icon-access-delete"
)
break
}
default:
break
}
})
}
Expand Down
Loading

0 comments on commit 78b3cfe

Please sign in to comment.