From e26e5cec79a6ed09229129380c4aa25735eba6ef Mon Sep 17 00:00:00 2001 From: jackahl Date: Wed, 6 Dec 2023 11:21:03 +0100 Subject: [PATCH] add formatting and linting files --- .editorconfig | 34 +++++++++++++++++++ .eslintignore | 6 ++++ .eslintrc | 53 ++++++++++++++++++++++++++++++ .prettierignore | 3 ++ .prettierrc | 12 +++++++ .stylelintrc | 32 ++++++++++++++++++ package.json | 61 ++++++++++++++++++++++++++++++++--- src/components/Logo/Data.jsx | 12 +++---- src/components/Logo/Edit.jsx | 8 ++--- src/components/Logo/View.jsx | 16 ++++----- src/components/Logo/schema.js | 38 +++++++++++----------- src/components/index.js | 4 +-- src/index.js | 25 +++++++------- src/theme/main.less | 18 +++++------ yarn.lock | 55 ++++++++++++++++++++++++++----- 15 files changed, 302 insertions(+), 75 deletions(-) create mode 100644 .editorconfig create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .prettierignore create mode 100644 .prettierrc create mode 100644 .stylelintrc diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6c43b88 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,34 @@ +# EditorConfig Configurtaion file, for more details see: +# http://EditorConfig.org +# EditorConfig is a convention description, that could be interpreted +# by multiple editors to enforce common coding conventions for specific +# file types + +# top-most EditorConfig file: +# Will ignore other EditorConfig files in Home directory or upper tree level. +root = true + + +[*] # For All Files +# Unix-style newlines with a newline ending every file +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +# Set default charset +charset = utf-8 +# Indent style default +indent_style = space + +[*.{py,cfg,ini}] +# 4 space indentation +indent_size = 4 + +[*.{html,dtml,pt,zpt,xml,zcml,js,jsx,json,less,css,yaml,yml}] +# 2 space indentation +indent_size = 2 + +[{Makefile,.gitmodules}] +# Tab indentation (no size specified, but view as 4 spaces) +indent_style = tab +indent_size = unset +tab_width = unset diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..efb3c8d --- /dev/null +++ b/.eslintignore @@ -0,0 +1,6 @@ +container-query-polyfill.modern.js +cypress +node_modules +acceptance +*.json +remove_me diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..886d9d7 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,53 @@ +{ + "extends": ["react-app", "prettier", "plugin:jsx-a11y/recommended"], + "plugins": ["prettier", "react-hooks", "jsx-a11y"], + "env": { + "es6": true, + "browser": true, + "node": true, + "mocha": true, + "jasmine": true + }, + "parser": "@babel/eslint-parser", + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module", + "ecmaFeatures": { + "legacyDecorators": true + } + }, + "rules": { + "import/no-unresolved": 0, + "no-alert": 1, + "no-console": 1, + "no-debugger": 1, + "prettier/prettier": [ + "error", + { "trailingComma": "all", "singleQuote": true } + ], + "react-hooks/rules-of-hooks": "error", + "react-hooks/exhaustive-deps": "warn", + "react/react-in-jsx-scope": "off" + }, + "settings": { + "react": { + "version": "17.0.2" + } + }, + "globals": { + "root": true, + "__DEVELOPMENT__": true, + "__CLIENT__": true, + "__SERVER__": true, + "__DISABLE_SSR__": true, + "__DEVTOOLS__": true, + "__DEBUG__": true, + "__SSR__": true, + "__SENTRY__": true, + "cy": true, + "Cypress": true, + "jest": true, + "socket": true, + "webpackIsomorphicTools": true + } +} diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..0899fca --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +container-query-polyfill.modern.js +CHANGELOG.md +README.md diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..fd5b441 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,12 @@ +{ + "trailingComma": "all", + "singleQuote": true, + "overrides": [ + { + "files": "*.overrides", + "options": { + "parser": "less" + } + } + ] +} diff --git a/.stylelintrc b/.stylelintrc new file mode 100644 index 0000000..09d4a27 --- /dev/null +++ b/.stylelintrc @@ -0,0 +1,32 @@ +{ + "extends": [ + "stylelint-config-idiomatic-order" + ], + "plugins": [ + "stylelint-prettier" + ], + "overrides": [ + { + "files": [ + "**/*.less" + ], + "customSyntax": "postcss-less" + }, + { + "files": [ + "**/*.overrides" + ], + "customSyntax": "postcss-less" + }, + { + "files": [ + "**/*.scss" + ], + "customSyntax": "postcss-scss" + } + ], + "rules": { + "prettier/prettier": true, + "order/properties-alphabetical-order": null + } +} diff --git a/package.json b/package.json index 834a185..c299944 100644 --- a/package.json +++ b/package.json @@ -21,28 +21,79 @@ "release-alpha": "release-it --preRelease=alpha", "release-rc": "release-it --preRelease=rc" }, + "prettier": { + "trailingComma": "all", + "singleQuote": true, + "useTabs": false, + "overrides": [ + { + "files": "*.overrides", + "options": { + "parser": "less" + } + } + ] + }, + "stylelint": { + "extends": [ + "stylelint-config-idiomatic-order" + ], + "plugins": [ + "stylelint-prettier" + ], + "overrides": [ + { + "files": [ + "**/*.less" + ], + "customSyntax": "postcss-less" + }, + { + "files": [ + "**/*.overrides" + ], + "customSyntax": "postcss-less" + } + ], + "rules": { + "prettier/prettier": true, + "rule-empty-line-before": [ + "always-multi-line", + { + "except": [ + "first-nested" + ], + "ignore": [ + "after-comment" + ] + } + ] + } + }, "devDependencies": { "@babel/eslint-parser": "7.22.15", "@plone/scripts": "^3.0.0", "eslint": "8.49.0", "eslint-config-prettier": "9.0.0", "eslint-config-react-app": "7.0.1", - "eslint-plugin-flowtype": "8.0.3", + "eslint-import-resolver-alias": "1.1.2", + "eslint-import-resolver-babel-plugin-root-import": "1.1.1", "eslint-plugin-import": "2.28.1", "eslint-plugin-jsx-a11y": "6.7.1", "eslint-plugin-prettier": "5.0.0", "eslint-plugin-react": "7.33.2", "eslint-plugin-react-hooks": "4.6.0", "postcss-less": "6.0.0", - "postcss-scss": "4.0.8", "prettier": "3.0.3", - "release-it": "^16.1.5", + "release-it": "^16.2.1", "stylelint": "15.10.3", "stylelint-config-idiomatic-order": "9.0.0", + "stylelint-config-prettier": "9.0.4", "stylelint-config-sass-guidelines": "10.0.0", "stylelint-prettier": "4.0.2" }, "peerDependencies": { - "@plone/volto": "^17.0.0" - } + "@plone/volto": "^17.0.0-alpha.21" + }, + "packageManager": "yarn@3.2.3" } diff --git a/src/components/Logo/Data.jsx b/src/components/Logo/Data.jsx index 57f9435..17e8488 100644 --- a/src/components/Logo/Data.jsx +++ b/src/components/Logo/Data.jsx @@ -1,12 +1,12 @@ -import React from "react"; -import { BlockDataForm } from "@plone/volto/components"; -import { LogoBlockSchema } from "./schema"; -import { useIntl, defineMessages } from "react-intl"; +import React from 'react'; +import { BlockDataForm } from '@plone/volto/components'; +import { LogoBlockSchema } from './schema'; +import { useIntl, defineMessages } from 'react-intl'; const messages = defineMessages({ Logo: { - id: "Logo", - defaultMessage: "Logo", + id: 'Logo', + defaultMessage: 'Logo', }, }); diff --git a/src/components/Logo/Edit.jsx b/src/components/Logo/Edit.jsx index 3a8d186..c497a7a 100644 --- a/src/components/Logo/Edit.jsx +++ b/src/components/Logo/Edit.jsx @@ -1,7 +1,7 @@ -import React from "react"; -import View from "./View"; -import { SidebarPortal } from "@plone/volto/components"; -import LogoBlockSidebar from "./Data"; +import React from 'react'; +import View from './View'; +import { SidebarPortal } from '@plone/volto/components'; +import LogoBlockSidebar from './Data'; const Edit = (props) => { const { data, block, onChangeBlock, selected } = props; diff --git a/src/components/Logo/View.jsx b/src/components/Logo/View.jsx index 6e4a606..146897f 100644 --- a/src/components/Logo/View.jsx +++ b/src/components/Logo/View.jsx @@ -1,13 +1,13 @@ -import React from "react"; -import { flattenToAppURL } from "@plone/volto/helpers"; -import { Message } from "semantic-ui-react"; -import { defineMessages, useIntl } from "react-intl"; -import imageBlockSVG from "@plone/volto/components/manage/Blocks/Image/block-image.svg"; +import React from 'react'; +import { flattenToAppURL } from '@plone/volto/helpers'; +import { Message } from 'semantic-ui-react'; +import { defineMessages, useIntl } from 'react-intl'; +import imageBlockSVG from '@plone/volto/components/manage/Blocks/Image/block-image.svg'; const messages = defineMessages({ PleaseChooseLogo: { - id: "Please choose a logo as source for this element", - defaultMessage: "Please choose a logo as source for this element", + id: 'Please choose a logo as source for this element', + defaultMessage: 'Please choose a logo as source for this element', }, }); @@ -27,7 +27,7 @@ const View = (props) => { )} {logo && ( placeholder diff --git a/src/components/Logo/schema.js b/src/components/Logo/schema.js index 71e7a37..5286f6d 100644 --- a/src/components/Logo/schema.js +++ b/src/components/Logo/schema.js @@ -1,44 +1,44 @@ -import { defineMessages } from "react-intl"; +import { defineMessages } from 'react-intl'; const messages = defineMessages({ logo: { - id: "Logo", - defaultMessage: "Logo", + id: 'Logo', + defaultMessage: 'Logo', }, title: { - id: "title", - defaultMessage: "title", + id: 'title', + defaultMessage: 'title', }, description: { - id: "description", - defaultMessage: "description", + id: 'description', + defaultMessage: 'description', }, logoBlock: { - id: "Logo", - defaultMessage: "Logo", + id: 'Logo', + defaultMessage: 'Logo', }, svgbest: { - id: "It is advised to use a svg graphic.", - defaultMessage: "It is advised to use a svg graphic.", + id: 'It is advised to use a svg graphic.', + defaultMessage: 'It is advised to use a svg graphic.', }, }); export const LogoBlockSchema = (props) => { return { title: props.intl.formatMessage(messages.logoBlock), - block: "logo", + block: 'logo', fieldsets: [ { - id: "default", - title: "Default", - fields: ["logo", "heading", "description"], + id: 'default', + title: 'Default', + fields: ['logo', 'heading', 'description'], }, ], properties: { logo: { title: props.intl.formatMessage(messages.logo), - widget: "object_browser", - mode: "image", + widget: 'object_browser', + mode: 'image', allowExternals: true, description: props.intl.formatMessage(messages.svgbest), }, @@ -47,9 +47,9 @@ export const LogoBlockSchema = (props) => { }, description: { title: props.intl.formatMessage(messages.description), - widget: "text", + widget: 'text', }, }, - required: ["logo"], + required: ['logo'], }; }; diff --git a/src/components/index.js b/src/components/index.js index 2613bfe..7d97d41 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -1,4 +1,4 @@ -import LogoBlockEdit from "./Logo/Edit"; -import LogoBlockView from "./Logo/View"; +import LogoBlockEdit from './Logo/Edit'; +import LogoBlockView from './Logo/View'; export { LogoBlockEdit, LogoBlockView }; diff --git a/src/index.js b/src/index.js index 48f9a1b..816ab52 100644 --- a/src/index.js +++ b/src/index.js @@ -1,17 +1,15 @@ -import { LogoBlockView, LogoBlockEdit } from "./components"; -import GridBlockView from "@plone/volto/components/manage/Blocks/Grid/View"; -import GridBlockEdit from "@plone/volto/components/manage/Blocks/Grid/Edit"; -import { LogoBlockSchema } from "./components/Logo/schema"; +import { LogoBlockView, LogoBlockEdit } from './components'; +import { LogoBlockSchema } from './components/Logo/schema'; -import freedomSVG from "@plone/volto/icons/freedom.svg"; +import freedomSVG from '@plone/volto/icons/freedom.svg'; -import "./theme/main.less"; +import './theme/main.less'; const applyConfig = (config) => { config.blocks.blocksConfig.logo = { - id: "logo", - title: "Logo", - group: "common", + id: 'logo', + title: 'Logo', + group: 'common', icon: freedomSVG, view: LogoBlockView, edit: LogoBlockEdit, @@ -22,18 +20,17 @@ const applyConfig = (config) => { }; config.blocks.blocksConfig.logos = { ...config.blocks.blocksConfig.gridBlock, - id: "logos", - title: "Logos", - group: "common", + id: 'logos', + title: 'Logos', + group: 'common', mostUsed: true, icon: freedomSVG, - allowedBlocks: ["logo"], + allowedBlocks: ['logo'], sidebarTab: 1, }; config.blocks.blocksConfig.logos.blocksConfig = { ...config.blocks.blocksConfig, }; - console.log(config); return config; }; diff --git a/src/theme/main.less b/src/theme/main.less index 228b2bc..c5b0d13 100644 --- a/src/theme/main.less +++ b/src/theme/main.less @@ -8,27 +8,27 @@ } // general spacing in the Row block wrapper - & [class^="block-editor-"], - [class^="block-editor-"].contained { + & [class^='block-editor-'], + [class^='block-editor-'].contained { padding-right: 1rem; padding-left: 1rem; margin-top: 1rem; margin-bottom: 1rem; } - .one.grid-items [class^="block-editor-"] { + .one.grid-items [class^='block-editor-'] { width: 100%; } - .two.grid-items [class^="block-editor-"] { + .two.grid-items [class^='block-editor-'] { width: 50%; } - .three.grid-items [class^="block-editor-"] { + .three.grid-items [class^='block-editor-'] { width: 33.33333333%; } - .four.grid-items [class^="block-editor-"] { + .four.grid-items [class^='block-editor-'] { width: 25%; } @@ -58,15 +58,15 @@ } } - [class^="block-editor-"].selected .ui.basic.button.remove-block-button, - [class^="block-editor-"]:hover .ui.basic.button.remove-block-button { + [class^='block-editor-'].selected .ui.basic.button.remove-block-button, + [class^='block-editor-']:hover .ui.basic.button.remove-block-button { display: block; } .cell-wrapper { position: relative; - flex-grow: 1; width: 100%; + flex-grow: 1; } .logo-image { diff --git a/yarn.lock b/yarn.lock index e8c85cb..9744ef7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2408,6 +2408,13 @@ debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.4: dependencies: ms "2.1.2" +debug@^2.2.0: + version "2.6.9" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" + integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA== + dependencies: + ms "2.0.0" + debug@^3.2.7: version "3.2.7" resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.7.tgz#72580b7e9145fb39b6676f9c5e5fb100b934179a" @@ -2753,6 +2760,28 @@ eslint-config-react-app@7.0.1: eslint-plugin-react-hooks "^4.3.0" eslint-plugin-testing-library "^5.0.1" +eslint-import-resolver-alias@1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/eslint-import-resolver-alias/-/eslint-import-resolver-alias-1.1.2.tgz#297062890e31e4d6651eb5eba9534e1f6e68fc97" + integrity sha512-WdviM1Eu834zsfjHtcGHtGfcu+F30Od3V7I9Fi57uhBEwPkjDcii7/yW8jAT+gOhn4P/vOxxNAXbFAKsrrc15w== + +eslint-import-resolver-babel-plugin-root-import@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/eslint-import-resolver-babel-plugin-root-import/-/eslint-import-resolver-babel-plugin-root-import-1.1.1.tgz#b060f1177557918389f7ed476e5b36a43854a381" + integrity sha512-ZZxdV9AxzL2WFVggDxZ36xodPg2+BTrkhhMf/of+BxSVh/GKLGCs17EDq5b61wqC7/oQsA2h1RtH1fV7HOUV/w== + dependencies: + eslint-import-resolver-node "^0.2.1" + json5 "^0.5.0" + +eslint-import-resolver-node@^0.2.1: + version "0.2.3" + resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.2.3.tgz#5add8106e8c928db2cba232bcd9efa846e3da16c" + integrity sha512-HI8ShtDIy7gON76Nr3bu4zl0DuCLPo1Fud9P2lltOQKeiAS2r5/o/l3y+V8HJ1cDLFSz+tHu7/V9fI5jirwlbw== + dependencies: + debug "^2.2.0" + object-assign "^4.0.1" + resolve "^1.1.6" + eslint-import-resolver-node@^0.3.7, eslint-import-resolver-node@^0.3.9: version "0.3.9" resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.9.tgz#d4eaac52b8a2e7c3cd1903eb00f7e053356118ac" @@ -2769,7 +2798,7 @@ eslint-module-utils@^2.8.0: dependencies: debug "^3.2.7" -eslint-plugin-flowtype@8.0.3, eslint-plugin-flowtype@^8.0.3: +eslint-plugin-flowtype@^8.0.3: version "8.0.3" resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-8.0.3.tgz#e1557e37118f24734aa3122e7536a038d34a4912" integrity sha512-dX8l6qUL6O+fYPtpNRideCFSpmWOUVx5QcaGLVqe/vlDiBSe4vYljDWDETwnyFzpl7By/WVIu6rcrniCgH9BqQ== @@ -4043,6 +4072,11 @@ json-stable-stringify-without-jsonify@^1.0.1: resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" integrity sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw== +json5@^0.5.0: + version "0.5.1" + resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" + integrity sha512-4xrs1aW+6N5DalkqSVA8fxh458CXvR99WU8WLKmq4v8eWAL86Xo3BVqyd3SkA9wEVjCMqyvvRRkshAdOnBp5rw== + json5@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.2.tgz#63d98d60f21b313b77c4d6da18bfa69d80e1d593" @@ -4364,6 +4398,11 @@ mrs-developer@*: chalk "^2.4.2" simple-git "^3.3.0" +ms@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + integrity sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A== + ms@2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" @@ -4466,7 +4505,7 @@ npm-run-path@^5.1.0: dependencies: path-key "^4.0.0" -object-assign@^4.1.1: +object-assign@^4.0.1, object-assign@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg== @@ -4770,11 +4809,6 @@ postcss-safe-parser@^6.0.0: resolved "https://registry.yarnpkg.com/postcss-safe-parser/-/postcss-safe-parser-6.0.0.tgz#bb4c29894171a94bc5c996b9a30317ef402adaa1" integrity sha512-FARHN8pwH+WiS2OPCxJI8FuRJpTVnn6ZNFiqAM2aeW2LwTHWWmWgIyKC6cUo0L8aeKiF/14MNvnpls6R2PBeMQ== -postcss-scss@4.0.8: - version "4.0.8" - resolved "https://registry.yarnpkg.com/postcss-scss/-/postcss-scss-4.0.8.tgz#12a4991a902a782d4e9b86b1f217d5181c6c4f32" - integrity sha512-Cr0X8Eu7xMhE96PJck6ses/uVVXDtE5ghUTKNUYgm8ozgP2TkgV3LWs3WgLV1xaSSLq8ZFiXaUrj0LVgG1fGEA== - postcss-scss@^4.0.6: version "4.0.9" resolved "https://registry.yarnpkg.com/postcss-scss/-/postcss-scss-4.0.9.tgz#a03c773cd4c9623cb04ce142a52afcec74806685" @@ -5032,7 +5066,7 @@ regjsparser@^0.9.1: dependencies: jsesc "~0.5.0" -release-it@^16.1.5: +release-it@^16.2.1: version "16.3.0" resolved "https://registry.yarnpkg.com/release-it/-/release-it-16.3.0.tgz#d962283fd72cc24d80d1956fcc020922326f7a5a" integrity sha512-CP+WwKbgEvXreq6Iz9po3BtcyELtTxrt5RXRGnazQ0eCphPxFZR29+8sEZRCsJq2IKvlwb5mFUbf92u426oQog== @@ -5524,6 +5558,11 @@ stylelint-config-idiomatic-order@9.0.0: dependencies: stylelint-order "^5.0.0" +stylelint-config-prettier@9.0.4: + version "9.0.4" + resolved "https://registry.yarnpkg.com/stylelint-config-prettier/-/stylelint-config-prettier-9.0.4.tgz#1b1dda614d5b3ef6c1f583fa6fa55f88245eb00b" + integrity sha512-38nIGTGpFOiK5LjJ8Ma1yUgpKENxoKSOhbDNSemY7Ep0VsJoXIW9Iq/2hSt699oB9tReynfWicTAoIHiq8Rvbg== + stylelint-config-sass-guidelines@10.0.0: version "10.0.0" resolved "https://registry.yarnpkg.com/stylelint-config-sass-guidelines/-/stylelint-config-sass-guidelines-10.0.0.tgz#ace99689eb6769534c9b40d62e2a8562b1ddc9f2"