diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..bcaa1393 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +webpack/js-yaml.js diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..6c79457e --- /dev/null +++ b/.eslintrc @@ -0,0 +1,13 @@ +{ + "plugins": ["@theforeman/foreman"], + "extends": [ + "plugin:@theforeman/foreman/core", + "plugin:@theforeman/foreman/plugins", + ], + "rules": { + // avoid https://github.com/prettier/eslint-config-prettier/issues/29 + "standard/computed-property-even-spacing": 0, + //"eqeqeq": "warn", + "max-lines": ["error", {"max": 650, "skipBlankLines": true, "skipComments": true}], + }, +} diff --git a/.github/workflows/javascript_tests.yml b/.github/workflows/javascript_tests.yml index cf480099..d377c3f6 100644 --- a/.github/workflows/javascript_tests.yml +++ b/.github/workflows/javascript_tests.yml @@ -22,8 +22,7 @@ jobs: - run: npm install - name: Linting run: | - # FIXME: we need to fix the findings, first - #npm run lint + npm run lint npm run stylelint - name: Testing run: npm run test diff --git a/jest.config.js b/jest.config.js index 0eca6d15..ca60d8a5 100644 --- a/jest.config.js +++ b/jest.config.js @@ -12,6 +12,7 @@ module.exports = { collectCoverage: true, collectCoverageFrom: [ 'webpack/**/*.js', + '!webpack/js-yaml.js', '!webpack/index.js', '!webpack/test_setup.js', '!webpack/**/bundle*', diff --git a/package.json b/package.json index dbfc9b33..ac0d450a 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "babel-preset-env": "^1.6.0", "babel-preset-react": "^6.24.1", "eslint": "^6.7.2", + "eslint-plugin-react": "^7.34.1", "jest": "^23.6.0", "jest-prop-type-error": "^1.1.0", "lodash": "^4.17.11", @@ -26,8 +27,8 @@ "table-resolver": "^3.2.0" }, "scripts": { - "lint": "tfm-lint --plugin -d *.js,webpack", - "lint-fix": "tfm-lint --plugin -d *.js,webpack --fix", + "lint": "eslint *.js webpack", + "lint-fix": "eslint --fix *.js webpack", "stylelint": "stylelint webpack/**/*.scss", "stylelint-fix": "stylelint webpack/**/*.scss --fix", "test": "jest --no-cache" diff --git a/webpack/components/ApplicationDefinition/ApplicationDefinition.js b/webpack/components/ApplicationDefinition/ApplicationDefinition.js index 3eec140b..4c4d2a6c 100644 --- a/webpack/components/ApplicationDefinition/ApplicationDefinition.js +++ b/webpack/components/ApplicationDefinition/ApplicationDefinition.js @@ -1,50 +1,43 @@ -import $ from 'jquery'; -import React, { useState } from 'react' +import React from 'react'; import PropTypes from 'prop-types'; import { Icon, Button, MessageDialog, + Table, + FormControl, + inlineEditFormatterFactory, } from 'patternfly-react'; import * as resolve from 'table-resolver'; import ForemanModal from 'foremanReact/components/ForemanModal'; import Select from 'foremanReact/components/common/forms/Select'; +import { translate as __ } from 'foremanReact/common/I18n'; import ParameterSelection from '../ParameterSelection'; import AddTableEntry from '../common/AddTableEntry'; import DeleteTableEntry from '../common/DeleteTableEntry'; import RailsData from '../common/RailsData'; import AnsiblePlaybookSelector from './components/AnsiblePlaybookSelector'; -import { translate as __ } from 'foremanReact/common/I18n'; import { EasyHeaderFormatter } from '../../helper'; -import { - Table, - FormControl, - inlineEditFormatterFactory, -} from 'patternfly-react'; - import { PARAMETER_SELECTION_PARAM_TYPE_FOREMAN, PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE, } from '../ParameterSelection/ParameterSelectionConstants'; class ApplicationDefinition extends React.Component { - - constructor(props) { - super(props); - } - - isEditing({rowData}) { - return (rowData.backup !== undefined); + static isEditing({ rowData }) { + return rowData.backup !== undefined; } - createAnsibleGroupObject(ansibleGroups, withAll=false) { + static createAnsibleGroupObject(ansibleGroups, withAll = false) { const ansibleGroupObj = {}; const ansibleGroupArray = Object.keys(ansibleGroups); - ansibleGroupArray.forEach(e => (ansibleGroupObj[e] = e)); + ansibleGroupArray.forEach(e => { + ansibleGroupObj[e] = e; + }); - if ((withAll === false) && (ansibleGroupObj.hasOwnProperty('all'))) { + if (withAll === false && ansibleGroupObj.hasOwnProperty('all')) { delete ansibleGroupObj.all; } @@ -52,20 +45,24 @@ class ApplicationDefinition extends React.Component { } addTableEntryAllowed() { - return this.props.editMode || this.props.ansiblePlaybook.id == '' + return this.props.editMode || this.props.ansiblePlaybook.id === ''; } componentDidMount() { const { - data: { mode, ansiblePlaybook, ansibleDataUrl, services, ansibleVarsAll, hostgroups, supportedPlugins }, + data: { + ansiblePlaybook, + services, + ansibleVarsAll, + hostgroups, + supportedPlugins, + }, initApplicationDefinition, - addApplicationDefinitionService, deleteApplicationDefinitionService, activateEditApplicationDefinitionService, changeEditApplicationDefinitionService, openForemanParameterSelectionModal, openAnsibleParameterSelectionModal, - loadAnsibleData, } = this.props; const inlineEditButtonsFormatter = inlineEditFormatterFactory({ @@ -74,23 +71,25 @@ class ApplicationDefinition extends React.Component {       (     -