add linting

This commit is contained in:
mahula 2024-02-19 17:56:22 +01:00
parent 8982c206de
commit b4c161fd82
9 changed files with 2760 additions and 98 deletions

1
.eslintignore Normal file
View File

@ -0,0 +1 @@
node_modules/

158
.eslintrc.cjs Normal file
View File

@ -0,0 +1,158 @@
// eslint-disable-next-line import/no-commonjs
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'standard',
'eslint:recommended',
'plugin:@eslint-community/eslint-comments/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:security/recommended-legacy',
],
parserOptions: {
ecmaVersion: 'latest',
parser: '@typescript-eslint/parser',
sourceType: 'module',
},
plugins: ['cypress', '@typescript-eslint', 'import'],
settings: {
'import/resolver': {
typescript: true,
node: true,
},
},
rules: {
'no-console': 'error',
'no-debugger': 'error',
camelcase: 'error',
indent: ['error', 2],
'linebreak-style': ['error', 'unix'],
semi: ['error', 'never'],
// Optional eslint-comments rule
'@eslint-community/eslint-comments/no-unused-disable': 'error',
'@eslint-community/eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }],
// import
'import/export': 'error',
'import/no-deprecated': 'error',
'import/no-empty-named-blocks': 'error',
'import/no-extraneous-dependencies': 'error',
'import/no-mutable-exports': 'error',
'import/no-unused-modules': 'error',
'import/no-named-as-default': 'error',
'import/no-named-as-default-member': 'error',
'import/no-amd': 'error',
'import/no-commonjs': 'error',
'import/no-import-module-exports': 'error',
'import/no-nodejs-modules': 'off',
'import/unambiguous': 'off',
'import/default': 'error',
'import/named': 'error',
'import/namespace': 'error',
'import/no-absolute-path': 'error',
'import/no-cycle': 'error',
'import/no-dynamic-require': 'error',
'import/no-internal-modules': 'off',
'import/no-relative-packages': 'error',
'import/no-relative-parent-imports': [
'error',
{ ignore: ['#[src,root,components,pages,assets,layouts,stores,plugins,context,types]/*'] },
],
'import/no-self-import': 'error',
'import/no-unresolved': 'error',
'import/no-useless-path-segments': 'error',
'import/no-webpack-loader-syntax': 'error',
'import/consistent-type-specifier-style': 'error',
'import/exports-last': 'off',
'import/extensions': [
'error',
'never',
{
json: 'always',
},
],
'import/first': 'error',
'import/group-exports': 'off',
'import/newline-after-import': 'error',
'import/no-anonymous-default-export': 'off', // todo - consider to enable again
'import/no-default-export': 'off', // incompatible with vite & vike
'import/no-duplicates': 'error',
'import/no-named-default': 'error',
'import/no-namespace': 'error',
'import/no-unassigned-import': 'error',
'import/order': [
'error',
{
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object', 'type'],
'newlines-between': 'always',
alphabetize: {
order: 'asc', // sort in ascending order. Options: ["ignore", "asc", "desc"]
caseInsensitive: true, // ignore case. Options: [true, false]
},
distinctGroup: true,
},
],
'import/prefer-default-export': 'off',
// promise
'promise/catch-or-return': 'error',
'promise/no-return-wrap': 'error',
'promise/param-names': 'error',
'promise/always-return': 'error',
'promise/no-native': 'off',
'promise/no-nesting': 'warn',
'promise/no-promise-in-callback': 'warn',
'promise/no-callback-in-promise': 'warn',
'promise/avoid-new': 'warn',
'promise/no-new-statics': 'error',
'promise/no-return-in-finally': 'warn',
'promise/valid-params': 'warn',
'promise/prefer-await-to-callbacks': 'error',
'promise/no-multiple-resolved': 'error',
},
overrides: [
{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json', '**/tsconfig.json'],
ecmaVersion: 'latest',
parser: '@typescript-eslint/parser',
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:@typescript-eslint/strict',
],
rules: {
// allow explicitly defined dangling promises
'@typescript-eslint/no-floating-promises': ['error', { ignoreVoid: true }],
'no-void': ['error', { allowAsStatement: true }],
},
},
{
files: ['!*.json'],
plugins: ['prettier'],
extends: ['plugin:prettier/recommended'],
rules: {
'prettier/prettier': 'error',
},
},
{
files: ['*.json'],
plugins: ['json'],
extends: ['plugin:json/recommended-with-comments'],
},
{
files: ['*.yaml', '*.yml'],
parser: 'yaml-eslint-parser',
plugins: ['yml'],
extends: ['plugin:yml/prettier'],
},
],
}

14
.prettierrc.json Normal file
View File

@ -0,0 +1,14 @@
{
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"quoteProps": "as-needed",
"jsxSingleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"bracketSameLine": false,
"arrowParens": "always",
"endOfLine": "auto"
}

View File

@ -1,6 +1,6 @@
import { defineConfig } from 'cypress'
import { addCucumberPreprocessorPlugin } from '@badeball/cypress-cucumber-preprocessor'
import webpack from '@cypress/webpack-preprocessor'
import { defineConfig } from 'cypress'
const setupNodeEvents = async (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) => {
await addCucumberPreprocessorPlugin(on, config, {
@ -39,7 +39,7 @@ const setupNodeEvents = async (on: Cypress.PluginEvents, config: Cypress.PluginC
}),
)
return config;
return config
}
export default defineConfig({
@ -51,5 +51,5 @@ export default defineConfig({
retries: 0,
video: false,
setupNodeEvents,
}
},
})

View File

@ -1,16 +1,13 @@
import {
Given,
When,
Then,
} from '@badeball/cypress-cucumber-preprocessor'
import {loginPage} from '../../pages/LoginPage'
import {welcomePage} from '../../pages/WelcomePage'
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'
import { loginPage } from '../../pages/LoginPage'
import { welcomePage } from '../../pages/WelcomePage'
Given('The web browser is at the login page', () => {
cy.visit('/login')
})
When('I submit the credentials {string} {string}', (username:string, password: string) => {
When('I submit the credentials {string} {string}', (username: string, password: string) => {
loginPage.submitLogin(username, password)
})

View File

@ -1,9 +1,9 @@
class LoginPage {
usernameInput: string = '#username'
passwordInput:string = '#password'
passwordInput: string = '#password'
submitBtn: string = 'button[type=submit]'
submitLogin(username: string, password: string){
submitLogin(username: string, password: string) {
cy.get(this.usernameInput).type(username)
cy.get(this.passwordInput).type(password)
cy.get(this.submitBtn).click()

View File

@ -1,6 +1,6 @@
class WelcomePage {
successMessage: string = '.flash.success'
WelcomeHeader:string = '.subheader'
WelcomeHeader: string = '.subheader'
logoutBtn: string = 'a[href="/logout"]'
}

2630
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -25,16 +25,34 @@
"license": "Apache-2.0",
"scripts": {
"cypress:open": "cypress open --e2e --browser electron",
"cypress:run": "cypress run"
"cypress:run": "cypress run --e2e --browser electron",
"test:lint:eslint": "eslint --ext .ts,.tsx,.js,.jsx,.cjs,.json,.yml,.yaml --max-warnings 0 ."
},
"devDependencies": {
"@badeball/cypress-cucumber-preprocessor": "^20.0.1",
"@cypress/webpack-preprocessor": "^6.0.1",
"@eslint-community/eslint-plugin-eslint-comments": "^4.1.0",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"cypress": "^13.6.4",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^17.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-cypress": "^2.15.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-security": "^2.1.1",
"eslint-plugin-yml": "^1.12.2",
"multiple-cucumber-html-reporter": "^3.6.2",
"prettier": "^3.2.5",
"ts-loader": "^9.5.1",
"typescript": "^5.3.3"
},
"engines": {
"node": "^20.2.0"
},
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true,
"stepDefinitions": "cypress/e2e/step_definitions/**/*.{js,ts}",