Skip to content

Commit

Permalink
Configure and fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Nov 14, 2024
1 parent d4c0ca3 commit acebd59
Show file tree
Hide file tree
Showing 55 changed files with 831 additions and 703 deletions.
108 changes: 108 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
module.exports = {
parserOptions: {
sourceType: "module",
ecmaVersion: 2020,
ecmaFeatures: {
jsx: true
}
},
settings: {
react: {
version: "18"
},
},
plugins: ["@stylistic/eslint-plugin", "react"],
extends: [],
rules: {
"jsx-quotes": 1,
"react/react-in-jsx-scope": 0,
"react/react-in-jsx-scope": 0,
"react/display-name": 0,
"react/forbid-prop-types": 0,
"react/jsx-indent-props": 0,
"react/jsx-indent": 0,
"react/jsx-no-literals": 0,
"react/jsx-sort-prop-types": 0,
"react/jsx-sort-props": 0,
"react/jsx-max-props-per-line": 0,
"react/no-multi-comp": 0,
"react/jsx-no-bind": 0,
"react/no-string-refs": 0,
"react/jsx-boolean-value": 1,
"react/jsx-closing-bracket-location": 1,
"react/jsx-curly-spacing": 1,
"react/jsx-handler-names": 1,
"react/jsx-key": 1,
"react/jsx-no-duplicate-props": 1,
"react/jsx-no-undef": 1,
"react/jsx-pascal-case": 1,
"react/jsx-uses-react": 1,
"react/jsx-uses-vars": 1,
"react/no-danger": 1,
"react/no-deprecated": 1,
"react/no-did-mount-set-state": 1,
"react/no-did-update-set-state": 1,
"react/no-direct-mutation-state": 1,
"react/no-is-mounted": 1,
"react/no-set-state": 1,
"react/no-unknown-property": 1,
"react/prefer-es6-class": 1,
"react/prop-types": 1,
"react/self-closing-comp": 1,
"react/sort-comp": 1,
"no-console": ["error", {allow: ["warn", "error"]}],
"no-self-assign": ["error", {props: false}],
"brace-style": ["error", "1tbs", {allowSingleLine: true}],
"comma-dangle": ["off"],
"comma-spacing": ["error", {before: false, after: true}],
"dot-notation": "error",
"eol-last": ["error", "always"],
"no-irregular-whitespace": ["error"],
"@stylistic/indent": ["error", 2],
"@stylistic/no-mixed-spaces-and-tabs": ["error"],
"no-debugger": "error",
"no-floating-decimal": ["error"],
"no-multiple-empty-lines": ["error", {max: 1, maxBOF: 0, maxEOF: 0}],
"no-new-wrappers": "error",
"no-throw-literal": "error",
"no-trailing-spaces": ["error"],
"no-var": "error",
"object-shorthand": "error",
"prefer-const": ["error", {destructuring: "all"}],
"prefer-exponentiation-operator": "error",
"quote-props": ["error", "as-needed"],
"object-curly-spacing": ["error", "never"],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", {
anonymous: "never",
named: "never",
asyncArrow: "always",
}],
"space-in-parens": ["error", "never"],
"keyword-spacing": ["error", {before: true, after: true}],
"func-call-spacing": ["error", "never"],
"no-whitespace-before-property": ["error"],
"block-spacing": ["error", "always"],
"key-spacing": ["error", {
beforeColon: false,
afterColon: true,
mode: "minimum",
}],
"space-unary-ops": ["error", {
words: true,
nonwords: false,
overrides: {},
}],
"guard-for-in": ["warn"],
quotes: ["error", "double", {avoidEscape: true, allowTemplateLiterals: true}],
curly: ["error", "all"],
"prefer-template": ["error"],
"generator-star-spacing": ["error", {
before: false,
after: true,
anonymous: {before: false, after: true},
method: {before: true, after: false},
}],
"yield-star-spacing": ["error", {before: false, after: true}],
},
}
94 changes: 45 additions & 49 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
default_stages: [pre-commit]
exclude: ^(\.copier-answers\.yml)|.pixi$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-toml
- id: check-json
- id: detect-private-key
- id: end-of-file-fixer
exclude: \.min\.js$
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
hooks:
- id: ruff
files: src/panel_material_ui
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies:
- tomli
- repo: https://github.com/hoxbro/prettier-pre-commit
rev: v3.3.3
hooks:
- id: prettier
entry: prettier --write --ignore-unknown --no-error-on-unmatched-pattern
types_or: [css]
- repo: https://github.com/shssoichiro/oxipng
rev: v8.0.0
hooks:
- id: oxipng
stages: [manual]
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v9.13.0
hooks:
- id: eslint
args: ['-c', '.eslintrc.js', 'src/panel_material_ui/**/*.jsx', '--fix']
additional_dependencies:
- 'eslint@8.57.0'
- 'eslint-plugin-react@7.37.2'
- '@stylistic/eslint-plugin@1.6.3'
- repo: local
hooks:
# ensure pixi environments are up to date
Expand All @@ -11,59 +56,10 @@ repos:
always_run: true
require_serial: true
pass_filenames: false
# ruff
- id: ruff
name: ruff
entry: pixi run -e lint ruff check --fix --exit-non-zero-on-fix --force-exclude
language: system
types_or: [python, pyi]
require_serial: true
- id: ruff-format
name: ruff-format
entry: pixi run -e lint ruff format --force-exclude
language: system
types_or: [python, pyi]
require_serial: true
# mypy
- id: mypy
name: mypy
entry: pixi run -e default mypy
language: system
types: [python]
require_serial: true
# prettier
- id: prettier
name: prettier
entry: pixi run -e lint prettier --write --list-different --ignore-unknown
language: system
types: [text]
files: \.(md|yml|yaml)$
# taplo
- id: taplo
name: taplo
entry: pixi run -e lint taplo format
language: system
types: [toml]
# pre-commit-hooks
- id: trailing-whitespace-fixer
name: trailing-whitespace-fixer
entry: pixi run -e lint trailing-whitespace-fixer
language: system
types: [text]
- id: end-of-file-fixer
name: end-of-file-fixer
entry: pixi run -e lint end-of-file-fixer
language: system
types: [text]
- id: check-merge-conflict
name: check-merge-conflict
entry: pixi run -e lint check-merge-conflict --assume-in-merge
language: system
types: [text]
# typos
- id: typos
name: typos
entry: pixi run -e lint typos --force-exclude
language: system
types: [text]
require_serial: true
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
recursive-include panel_material_ui models/*.js
recursive-include panel_material_ui models/*.js
18 changes: 11 additions & 7 deletions examples/components.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import inspect

from itertools import product
from typing import Type

import panel as pn
import param

from panel_material_ui import *
from panel_material_ui.base import MaterialComponent

pn.extension(template='material', defer_load=True)

from itertools import chain


def insert_at_nth_position(main_list, insert_list, n):
# Split main_list into chunks of size n
chunks = [main_list[i:i+n] for i in range(0, len(main_list), n)]
Expand All @@ -32,7 +36,7 @@ def render_variant(component, variant, **kwargs):
if isinstance(component.param[p], param.Integer):
values.append(list(range(10)))
elif isinstance(component.param[p], param.Boolean):
values.append((False, True))
values.append([False, True])
else:
values.append(component.param[p].objects)
combinations = product(*values)
Expand Down Expand Up @@ -80,11 +84,11 @@ def render_spec(spec, depth=0, label='main'):
return tabs


def render_openable(component, **kwargs):
close = Button(on_click=lambda _: backdrop.param.update(open=False), label='Close')
backdrop = component(CircularProgress(), close)
button = Button(on_click=lambda _: backdrop.param.update(open=True), label=f'Open {component.name}')
col = pn.Column(button, backdrop)
def render_openable(component: Type[MaterialComponent], **kwargs):
close = Button(on_click=lambda _: inst.param.update(open=False), label='Close') # type: ignore
inst = component(LoadingIndicator(), close)
button = Button(on_click=lambda _: inst.param.update(open=True), label=f'Open {component.name}')
col = pn.Column(button, inst)
return col

spec = {
Expand Down Expand Up @@ -131,7 +135,7 @@ def render_openable(component, **kwargs):
],
'Input': [
(Checkbox, (['size', 'value'],), dict(label='I agree to the terms and conditions')),
(FileInput, (['button_type', 'button_style'],), dict()),
(FileInput, (['button_type', 'button_style'],), {}),
(Switch, (['color', 'disabled'],), dict(label='Switch me!', value=True)),
(TextAreaInput, (['color', 'variant'], ['disabled']), dict(label='TextAreaInput')),
(TextInput, (['color', 'variant'], ['disabled', 'error_state']), dict(label='TextInput')),
Expand Down
82 changes: 41 additions & 41 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,53 @@ repo_url: https://github.com/panel-extensions/panel-material-ui
repo_name: philippjfr/panel-material-ui

theme:
name: material
logo: 'assets/logo.svg'
features:
- content.copy.code
palette:
# Palette toggle for light mode
- media: "(prefers-color-scheme: light)"
scheme: default
primary: white
accent: blue
toggle:
icon: material/brightness-7
name: Switch to dark mode
name: material
logo: "assets/logo.svg"
features:
- content.copy.code
palette:
# Palette toggle for light mode
- media: "(prefers-color-scheme: light)"
scheme: default
primary: white
accent: blue
toggle:
icon: material/brightness-7
name: Switch to dark mode

# Palette toggle for dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
primary: black
accent: blue
toggle:
icon: material/brightness-4
name: Switch to light mode
# Palette toggle for dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
primary: black
accent: blue
toggle:
icon: material/brightness-4
name: Switch to light mode

markdown_extensions:
- toc:
permalink: true
- pymdownx.highlight:
anchor_linenums: true
- pymdownx.tasklist:
custom_checkbox: true
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.superfences
- admonition
- toc:
permalink: true
- pymdownx.highlight:
anchor_linenums: true
- pymdownx.tasklist:
custom_checkbox: true
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.superfences
- admonition

plugins:
- search
- mkdocstrings:
handlers:
python:
options:
docstring_style: google
- search
- mkdocstrings:
handlers:
python:
options:
docstring_style: google

watch:
- docs
- docs

nav:
- Home: index.md
- Reference:
- panel-material-ui: reference/panel-material-ui.md
- Home: index.md
- Reference:
- panel-material-ui: reference/panel-material-ui.md
7 changes: 0 additions & 7 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ check-wheel = "twine check dist/*"

[feature.lint.dependencies]
pre-commit = "*"
insert-license-header = "*"
docformatter = "*"
ruff = "*"
prettier = "*"
taplo = "*"
pre-commit-hooks = "*"
typos = "*"
[feature.lint.tasks]
pre-commit-install = "pre-commit install"
pre-commit-run = "pre-commit run -a"
Expand Down
Loading

0 comments on commit acebd59

Please sign in to comment.