From 418d0596e7bfac844509ce31b9ec2e2bf574def4 Mon Sep 17 00:00:00 2001 From: Aaron Zielstorff Date: Fri, 30 Aug 2024 22:03:04 +0200 Subject: [PATCH] adds eslint and action for lint checking --- ...{build-aas-ui.yml => build-aas-web-ui.yml} | 0 .github/workflows/lint-aas-web-ui.yml | 27 + .github/workflows/prettier.yml | 35 - aas-web-ui/eslint.config.mjs | 97 ++ aas-web-ui/package.json | 17 +- aas-web-ui/src/App.vue | 7 +- .../src/UserPlugins/HelloWorldPlugin.vue | 23 +- aas-web-ui/src/components/AASTreeview.vue | 85 +- aas-web-ui/src/components/AASViewer.vue | 3 +- aas-web-ui/src/components/About.vue | 12 +- .../src/components/AppNavigation/AASList.vue | 162 ++-- .../AppNavigation/AASListDetails.vue | 40 +- .../AppNavigation/AppNavigation.vue | 275 +++--- .../src/components/AppNavigation/AutoSync.vue | 17 +- .../src/components/AppNavigation/MainMenu.vue | 92 +- .../components/AppNavigation/RegisterAAS.vue | 16 +- .../src/components/AppNavigation/Settings.vue | 3 +- .../AppNavigation/Settings/StatusSwitch.vue | 12 +- .../AppNavigation/Settings/ThemeSwitch.vue | 18 +- .../components/AppNavigation/UploadAAS.vue | 8 +- .../src/components/ComponentVisualization.vue | 120 ++- .../src/components/Dashboard/Dashboard.vue | 20 +- .../Dashboard/DashboardEditElement.vue | 25 +- .../components/Dashboard/DashboardElement.vue | 70 +- .../components/Dashboard/DashboardGroup.vue | 18 +- aas-web-ui/src/components/MainWindow.vue | 26 +- .../src/components/SubmodelElementView.vue | 191 ++-- .../AnnotatedRelationshipElement.vue | 4 +- .../src/components/SubmodelElements/Blob.vue | 65 +- .../components/SubmodelElements/Entity.vue | 27 +- .../src/components/SubmodelElements/File.vue | 47 +- .../SubmodelElements/InvalidElement.vue | 22 +- .../MultiLanguageProperty.vue | 61 +- .../components/SubmodelElements/Operation.vue | 89 +- .../components/SubmodelElements/Property.vue | 48 +- .../src/components/SubmodelElements/Range.vue | 10 +- .../SubmodelElements/ReferenceElement.vue | 80 +- .../SubmodelElements/RelationshipElement.vue | 82 +- .../components/SubmodelElements/Submodel.vue | 7 +- .../SubmodelElementCollection.vue | 7 +- .../SubmodelElements/SubmodelElementList.vue | 7 +- .../ValueTypes/BooleanType.vue | 83 +- .../ValueTypes/DateTimeStampType.vue | 87 +- .../ValueTypes/NumberType.vue | 66 +- .../ValueTypes/StringType.vue | 57 +- aas-web-ui/src/components/SubmodelList.vue | 73 +- .../SubmodelPlugins/BillsOfMaterial.vue | 37 +- .../components/SubmodelPlugins/CADPreview.vue | 49 +- .../SubmodelPlugins/ContactInformation.vue | 21 +- .../SubmodelPlugins/DigitalNameplate.vue | 31 +- .../HTWFuehrungskomponente.vue | 58 +- .../SubmodelPlugins/HandoverDocumentation.vue | 51 +- .../SubmodelPlugins/ImagePreview.vue | 36 +- .../SubmodelPlugins/JSONArrayProperty.vue | 52 +- .../components/SubmodelPlugins/PDFPreview.vue | 34 +- .../SubmodelPlugins/TechnicalData.vue | 25 +- .../SubmodelPlugins/TimeSeriesData.vue | 183 ++-- .../SubmodelPlugins/_SubmodelEntrypoint.vue | 55 +- .../UIComponents/AssetInformation.vue | 11 +- .../UIComponents/CollectionWrapper.vue | 19 +- .../UIComponents/ConceptDescription.vue | 32 +- .../UIComponents/DataSpecificationContent.vue | 62 +- .../UIComponents/DescriptionElement.vue | 6 +- .../UIComponents/DisplayNameElement.vue | 2 +- .../UIComponents/GenericDataVisu.vue | 59 +- .../UIComponents/IdentificationElement.vue | 14 +- .../components/UIComponents/SemanticID.vue | 4 +- .../UIComponents/SubmodelElementGroup.vue | 50 +- .../UIComponents/SubmodelElementWrapper.vue | 31 +- .../src/components/UIComponents/VTreeview.vue | 32 +- .../src/components/Widgets/AreaChart.vue | 48 +- .../src/components/Widgets/BarChart.vue | 32 +- aas-web-ui/src/components/Widgets/Button.vue | 15 +- .../src/components/Widgets/ColumnChart.vue | 32 +- .../src/components/Widgets/DisplayField.vue | 13 +- .../src/components/Widgets/DonutChart.vue | 36 +- aas-web-ui/src/components/Widgets/Gauge.vue | 36 +- .../src/components/Widgets/Histogram.vue | 53 +- .../src/components/Widgets/InputField.vue | 17 +- aas-web-ui/src/components/Widgets/Lamp.vue | 11 +- .../src/components/Widgets/LineChart.vue | 50 +- .../src/components/Widgets/RadialChart.vue | 34 +- .../src/components/Widgets/ScatterChart.vue | 46 +- aas-web-ui/src/components/Widgets/Switch.vue | 21 +- aas-web-ui/src/main.ts | 31 +- aas-web-ui/src/mixins/DashboardHandling.ts | 66 +- aas-web-ui/src/mixins/RequestHandling.ts | 16 +- .../src/mixins/SubmodelElementHandling.ts | 58 +- aas-web-ui/src/mixins/WidgetHandling.ts | 28 +- aas-web-ui/src/plugins/index.ts | 7 +- aas-web-ui/src/plugins/vuetify.ts | 1 - aas-web-ui/src/router.ts | 8 +- aas-web-ui/src/store/AuthStore.ts | 3 +- aas-web-ui/src/vue-shims.d.ts | 2 +- aas-web-ui/tsconfig.json | 2 +- .../{vite.config.ts => vite.config.mts} | 9 +- aas-web-ui/yarn.lock | 913 +++++++++++++++++- 97 files changed, 2859 insertions(+), 2024 deletions(-) rename .github/workflows/{build-aas-ui.yml => build-aas-web-ui.yml} (100%) create mode 100644 .github/workflows/lint-aas-web-ui.yml delete mode 100644 .github/workflows/prettier.yml create mode 100644 aas-web-ui/eslint.config.mjs rename aas-web-ui/{vite.config.ts => vite.config.mts} (83%) diff --git a/.github/workflows/build-aas-ui.yml b/.github/workflows/build-aas-web-ui.yml similarity index 100% rename from .github/workflows/build-aas-ui.yml rename to .github/workflows/build-aas-web-ui.yml diff --git a/.github/workflows/lint-aas-web-ui.yml b/.github/workflows/lint-aas-web-ui.yml new file mode 100644 index 00000000..8c33fb44 --- /dev/null +++ b/.github/workflows/lint-aas-web-ui.yml @@ -0,0 +1,27 @@ +name: Lint AAS Web UI + +on: + pull_request: + paths: + - 'aas-web-ui/**' + +jobs: + lint: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./aas-web-ui + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + + - name: Install Dependencies + run: yarn install + + - name: Run Linter + run: yarn lint:check diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml deleted file mode 100644 index 48ba78fd..00000000 --- a/.github/workflows/prettier.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Code Formatting - -on: - pull_request: - branches: [main] - paths: - - 'aas-web-ui/**' - -jobs: - prettier: - name: Prettier Check - runs-on: ubuntu-latest - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: '22' - - - name: Install Prettier - run: | - npm install --global prettier@latest - npm install --global prettier-plugin-vue - - - name: Run Prettier - run: | - cd aas-web-ui - prettier_output=$(prettier --check --config ./.prettierrc --ignore-path ./.prettierignore --no-error-on-unmatched-pattern **/*.ts **/*.vue **/*.json **/*.js) - echo "$prettier_output" - if ! echo "$prettier_output" | grep -q 'All matched files use Prettier code style!'; then - echo "Formatting issues found" - exit 1 - fi diff --git a/aas-web-ui/eslint.config.mjs b/aas-web-ui/eslint.config.mjs new file mode 100644 index 00000000..e86006f9 --- /dev/null +++ b/aas-web-ui/eslint.config.mjs @@ -0,0 +1,97 @@ +import js from '@eslint/js'; +import eslintConfigPrettier from 'eslint-config-prettier'; +import prettier from 'eslint-plugin-prettier'; +import pluginPromise from 'eslint-plugin-promise'; +import simpleImportSort from 'eslint-plugin-simple-import-sort'; +import vue from 'eslint-plugin-vue'; +import ts from 'typescript-eslint'; + +export default [ + { + ignores: ['{dist,public}/**/*', 'vue-shim.d.ts'], + }, + + { + languageOptions: { + ecmaVersion: 'latest', + }, + }, + + // js + js.configs.recommended, + + // ts + ...ts.configs.recommended, + { + rules: { + '@typescript-eslint/no-explicit-any': 'warn', + '@typescript-eslint/no-unused-expressions': ['error', { allowTernary: true }], + }, + }, + + // vue + ...vue.configs['flat/recommended'], + { + // files: ['*.vue', '**/*.vue'], + languageOptions: { + parserOptions: { + parser: ts.parser, + }, + }, + }, + { + rules: { + 'vue/multi-word-component-names': 'off', + 'vue/no-unused-vars': ['error', { ignorePattern: '^_' }], + 'vue/max-attributes-per-line': ['error', { singleline: 5 }], + }, + }, + + // Sort imports + { + plugins: { + 'simple-import-sort': simpleImportSort, + }, + rules: { + 'simple-import-sort/imports': [ + 'error', + { + groups: [ + [ + '^\\u0000', // all side effects (0 at start) + '^[^/\\.].*\u0000$', // external types (0 at end) + '^\\..*\u0000$', // internal types (0 at end) + '^@?\\w', // Starts with @ + '^[^.]', // any + '^\\.', // local + ], + ], + }, + ], + 'simple-import-sort/exports': 'error', + '@typescript-eslint/no-explicit-any': ['warn', { ignoreRestArgs: true }], + }, + }, + + // Promise + pluginPromise.configs['flat/recommended'], + { + rules: { + 'promise/always-return': 'off', + 'promise/catch-or-return': 'off', + }, + }, + + // Prettier + { + plugins: { + prettier, + }, + rules: { + 'prettier/prettier': 'error', + }, + }, + + // Disable rules that conflict with Prettier + eslintConfigPrettier, +]; diff --git a/aas-web-ui/package.json b/aas-web-ui/package.json index a33e0127..366fbc00 100644 --- a/aas-web-ui/package.json +++ b/aas-web-ui/package.json @@ -7,7 +7,9 @@ "scripts": { "dev": "vite", "build": "vue-tsc --noEmit && vite build", - "preview": "vite preview" + "preview": "vite preview", + "lint:check": "eslint ./", + "lint:fix": "eslint --fix ./" }, "dependencies": { "@fontsource/roboto": "^5.0.14", @@ -30,18 +32,27 @@ "webfontloader": "^1.0.0" }, "devDependencies": { + "@eslint/js": "^9.9.1", + "@types/eslint__js": "^8.42.3", "@types/leaflet": "^1.9.12", "@types/md5": "^2.3.5", "@types/node": "^22.4.1", "@types/three": "^0.166.0", "@types/uuid": "^10.0.0", "@types/webfontloader": "^1.6.38", - "@types/lodash": "^4.17.7", "@vitejs/plugin-vue": "^5.1.2", - "prettier": "3.3.3", + "eslint": "^9.9.1", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.2.1", + "eslint-plugin-promise": "^7.1.0", + "eslint-plugin-simple-import-sort": "^12.1.1", + "eslint-plugin-vue": "^9.27.0", + "prettier": "^3.3.3", "sass": "^1.77.8", "typescript": "^5.5.4", + "typescript-eslint": "^8.3.0", "vite": "^5.4.2", + "vite-plugin-eslint": "^1.8.1", "vite-plugin-vuetify": "^2.0.4", "vue-tsc": "^2.0.29" } diff --git a/aas-web-ui/src/App.vue b/aas-web-ui/src/App.vue index 484f2be4..44174e31 100644 --- a/aas-web-ui/src/App.vue +++ b/aas-web-ui/src/App.vue @@ -16,12 +16,11 @@