Skip to content

Commit 6b69316

Browse files
authored
Merge pull request #10 from hidapple/improve/js
Introduce ESLint
2 parents 7200cee + 5ba2d5d commit 6b69316

File tree

6 files changed

+349
-87
lines changed

6 files changed

+349
-87
lines changed

.eslintrc.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es6": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:react/recommended"
9+
],
10+
"globals": {
11+
"Atomics": "readonly",
12+
"SharedArrayBuffer": "readonly"
13+
},
14+
"parser": "babel-eslint",
15+
"parserOptions": {
16+
"ecmaFeatures": {
17+
"jsx": true
18+
},
19+
"ecmaVersion": 2018,
20+
"sourceType": "module"
21+
},
22+
"plugins": [
23+
"react"
24+
],
25+
"rules": {
26+
"indent": [
27+
"error",
28+
2
29+
]
30+
}
31+
}

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"scripts": {
1010
"build": "webpack",
11-
"lint": "eslint -c .eslintrc src/**/*",
11+
"lint": "eslint -c .eslintrc.json src/web/**/*.jsx",
1212
"test": "jest"
1313
},
1414
"keywords": [
@@ -18,6 +18,13 @@
1818
"license": "GNU General Public License v3.0",
1919
"dependencies": {},
2020
"devDependencies": {
21+
"babel-eslint": "^10.0.3",
22+
"eslint": "^6.6.0",
23+
"eslint-config-airbnb": "^18.0.1",
24+
"eslint-plugin-import": "^2.18.2",
25+
"eslint-plugin-jsx-a11y": "^6.2.3",
26+
"eslint-plugin-react": "^7.16.0",
27+
"eslint-plugin-react-hooks": "^1.7.0",
2128
"graylog-web-plugin": "file:../graylog2-server/graylog2-web-interface/packages/graylog-web-plugin"
2229
}
2330
}

src/web/CommonNotificationSummary.jsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
43
import { Table, Button } from 'react-bootstrap';
5-
6-
import styles from './CommonNotificationSummary.css';
4+
import styles from 'CommonNotificationSummary.css';
75

86
class CommonNotificationSummary extends React.Component {
97
static propTypes = {
@@ -36,15 +34,15 @@ class CommonNotificationSummary extends React.Component {
3634
{displayDetails ? 'Less details' : 'More details'}
3735
</Button>
3836
{displayDetails && (
39-
<Table condensed hover className={styles.fixedTable}>
40-
<tbody>
41-
<tr>
42-
<td>Description</td>
43-
<td>{notification.description || 'No description given'}</td>
44-
</tr>
45-
{children}
46-
</tbody>
47-
</Table>
37+
<Table condensed hover className={styles.fixedTable}>
38+
<tbody>
39+
<tr>
40+
<td>Description</td>
41+
<td>{notification.description || 'No description given'}</td>
42+
</tr>
43+
{children}
44+
</tbody>
45+
</Table>
4846
)}
4947
</dd>
5048
</dl>

src/web/TeamsNotificationForm.jsx

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import lodash from 'lodash';
4-
5-
import {Input} from 'components/bootstrap';
4+
import { Input } from 'components/bootstrap';
65
import FormsUtils from 'util/FormsUtils';
76

87
const DEFAULT_MSG = `# --- [Event Definition] ---------------------------
@@ -64,64 +63,56 @@ class TeamsNotificationForm extends React.Component {
6463
this.propagateChange(name, FormsUtils.getValueFromInput(event.target));
6564
};
6665

67-
handleBodyTemplateChange = (nextValue) => {
68-
this.propagateChange('body_template', nextValue);
69-
};
70-
71-
handleRecipientsChange = (key) => {
72-
return nextValue => this.propagateChange(key, nextValue === '' ? [] : nextValue.split(','));
73-
};
74-
7566
render() {
7667
const { config, validation } = this.props;
77-
7868
return (
7969
<React.Fragment>
80-
<Input id="notification-webhookUrl"
81-
name="webhook_url"
82-
label="Webhook URL"
83-
type="text"
84-
bsStyle={validation.errors.webhook_url ? 'error' : null}
85-
help={lodash.get(validation, 'errors.webhook_url[0]',
86-
'Microsoft Teams Incoming Webhook URL')}
87-
value={config.webhook_url || ''}
88-
onChange={this.handleChange}
89-
required />
90-
<Input id="notification-graylogUrl"
91-
name="graylog_url"
92-
label="Graylog URL"
93-
type="text"
94-
bsStyle={validation.errors.graylog_url ? 'error' : null}
95-
help={lodash.get(validation, 'errors.graylog_url[0]',
96-
'URL to be attached in notification')}
97-
value={config.graylog_url || ''}
98-
onChange={this.handleChange}/>
99-
<Input id="notification-color"
100-
name="color"
101-
label="Color"
102-
type="text"
103-
bsStyle={validation.errors.color ? 'error' : null}
104-
help={lodash.get(validation, 'errors.color[0]', 'Color code')}
105-
value={config.color || ''}
106-
onChange={this.handleChange}/>
107-
<Input id="notification-message"
108-
name="message"
109-
label="Message"
110-
type="textarea"
111-
bsStyle={validation.errors.message ? 'error' : null}
112-
help={lodash.get(validation, 'errors.message[0]',
113-
'Detail message supporting basic Markdown syntax')}
114-
value={config.message || ''}
115-
onChange={this.handleChange}/>
116-
<Input id="notification-proxyUrl"
117-
name="proxy_url"
118-
label="Proxy URL"
119-
type="text"
120-
bsStyle={validation.errors.proxy_url ? 'error' : null}
121-
help={lodash.get(validation, 'errors.proxy_url[0]',
122-
'Proxy URL in the following format "http(s)://${HOST}:${PORT}"')}
123-
value={config.proxy_url || ''}
124-
onChange={this.handleChange}/>
70+
<Input
71+
id="notification-webhook-url"
72+
name="webhook_url"
73+
label="Webhook URL"
74+
type="text"
75+
bsStyle={validation.errors.webhook_url ? 'error' : null}
76+
help={lodash.get(validation, 'errors.webhook_url[0]', 'Microsoft Teams Incoming Webhook URL')}
77+
value={config.webhook_url || ''}
78+
onChange={this.handleChange}
79+
required />
80+
<Input
81+
id="notification-graylog-url"
82+
name="graylog_url"
83+
label="Graylog URL"
84+
type="text"
85+
bsStyle={validation.errors.graylog_url ? 'error' : null}
86+
help={lodash.get(validation, 'errors.graylog_url[0]', 'URL to be attached in notification')}
87+
value={config.graylog_url || ''}
88+
onChange={this.handleChange}/>
89+
<Input
90+
id="notification-color"
91+
name="color"
92+
label="Color"
93+
type="text"
94+
bsStyle={validation.errors.color ? 'error' : null}
95+
help={lodash.get(validation, 'errors.color[0]', 'Color code')}
96+
value={config.color || ''}
97+
onChange={this.handleChange}/>
98+
<Input
99+
id="notification-message"
100+
name="message"
101+
label="Message"
102+
type="textarea"
103+
bsStyle={validation.errors.message ? 'error' : null}
104+
help={lodash.get(validation, 'errors.message[0]', 'Detail message supporting basic Markdown syntax')}
105+
value={config.message || ''}
106+
onChange={this.handleChange}/>
107+
<Input
108+
id="notification-proxy-url"
109+
name="proxy_url"
110+
label="Proxy URL"
111+
type="text"
112+
bsStyle={validation.errors.proxy_url ? 'error' : null}
113+
help={lodash.get(validation, 'errors.proxy_url[0]', 'Proxy URL in the following format "http(s)://${HOST}:${PORT}"')}
114+
value={config.proxy_url || ''}
115+
onChange={this.handleChange}/>
125116
</React.Fragment>
126117
);
127118
}

src/web/index.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PluginStore.register(new PluginManifest({}, {
1010
displayName: 'Microsoft Teams Notification',
1111
formComponent: TeamsNotificationForm,
1212
summaryComponent: TeamsNotificationSummary,
13-
defaultConfig: TeamsNotificationForm.defaultConfig
14-
}
15-
]
13+
defaultConfig: TeamsNotificationForm.defaultConfig,
14+
},
15+
],
1616
}));

0 commit comments

Comments
 (0)