Skip to content

Commit 172e0b2

Browse files
authored
chore: add prettier (1/3): add packages, configurations, fix lint issues (nasa#6382)
* fix: remove redundant eslint rules * chore: bump `prettier` to v2.8.7 * docs: vue files to use html comments for licenses - Prettier's Vue parser freaks out if it sees a *.js style comment in a *.vue file. * docs: more licenses for vue files * fix: don't ignore *.vue files * fix: use defaults for tabWidth and printWidth * simplify .prettierignore * enforce a printWidth of 100 * fix: use `eslint-plugin-prettier`, remove conflicting rules * test: fix gauge tests (for real) * test: fix notebook test selectors * test: fix restrictedNotebook test selectors * test: remove useless assignment * lint: __dirname as global * lint: revert eslint config + whitespace changes, commit new config * style: remove unnecessary string concat of literals * test: fix missed gauge test * fix: use new eslint rules * feat: add blank `.git-blame-ignore-revs` file * docs: update to mention Prettier and format. * Revert "test: fix gauge tests (for real)" This reverts commit 6afad45. * Revert "test: fix notebook test selectors" This reverts commit 17fe1cb. * Revert "test: fix restrictedNotebook test selectors" This reverts commit 97e0ede. * Revert "test: fix missed gauge test" This reverts commit e2398fc. * test: fix gauge tests (no formatting) * test: update notebook e2e selectors (no formatting) * test: update restrictedNotebook e2e selectors (no formatting) * fix: temporarily disable lint check
1 parent 5df7971 commit 172e0b2

File tree

213 files changed

+4202
-2497
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

213 files changed

+4202
-2497
lines changed

Diff for: .circleci/config.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ jobs:
232232
workflows:
233233
overall-circleci-commit-status: #These jobs run on every commit
234234
jobs:
235-
- lint:
236-
name: node16-lint
237-
node-version: lts/gallium
235+
# - lint:
236+
# name: node16-lint
237+
# node-version: lts/gallium
238238
- unit-test:
239239
name: node18-chrome
240240
node-version: lts/hydrogen

Diff for: .eslintrc.js

+4-109
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ module.exports = {
99
"globals": {
1010
"_": "readonly"
1111
},
12+
"plugins": ["prettier"],
1213
"extends": [
1314
"eslint:recommended",
1415
"plugin:compat/recommended",
1516
"plugin:vue/recommended",
16-
"plugin:you-dont-need-lodash-underscore/compatible"
17+
"plugin:you-dont-need-lodash-underscore/compatible",
18+
"plugin:prettier/recommended"
1719
],
1820
"parser": "vue-eslint-parser",
1921
"parserOptions": {
@@ -26,6 +28,7 @@ module.exports = {
2628
}
2729
},
2830
"rules": {
31+
"prettier/prettier": "error",
2932
"you-dont-need-lodash-underscore/omit": "off",
3033
"you-dont-need-lodash-underscore/throttle": "off",
3134
"you-dont-need-lodash-underscore/flatten": "off",
@@ -50,20 +53,6 @@ module.exports = {
5053
}
5154
],
5255
"no-console": "off",
53-
"no-trailing-spaces": "error",
54-
"space-before-function-paren": [
55-
"error",
56-
{
57-
"anonymous": "always",
58-
"asyncArrow": "always",
59-
"named": "never"
60-
}
61-
],
62-
"array-bracket-spacing": "error",
63-
"space-in-parens": "error",
64-
"space-before-blocks": "error",
65-
"comma-dangle": "error",
66-
"eol-last": "error",
6756
"new-cap": [
6857
"error",
6958
{
@@ -72,7 +61,6 @@ module.exports = {
7261
}
7362
],
7463
"dot-notation": "error",
75-
"indent": ["error", 4],
7664

7765
// https://eslint.org/docs/rules/no-case-declarations
7866
"no-case-declarations": "error",
@@ -82,8 +70,6 @@ module.exports = {
8270
"no-eq-null": "error",
8371
// https://eslint.org/docs/rules/no-eval
8472
"no-eval": "error",
85-
// https://eslint.org/docs/rules/no-floating-decimal
86-
"no-floating-decimal": "error",
8773
// https://eslint.org/docs/rules/no-implicit-globals
8874
"no-implicit-globals": "error",
8975
// https://eslint.org/docs/rules/no-implied-eval
@@ -112,16 +98,10 @@ module.exports = {
11298
"no-unmodified-loop-condition": "error",
11399
// https://eslint.org/docs/rules/no-useless-call
114100
"no-useless-call": "error",
115-
// https://eslint.org/docs/rules/wrap-iife
116-
"wrap-iife": "error",
117101
// https://eslint.org/docs/rules/no-nested-ternary
118102
"no-nested-ternary": "error",
119-
// https://eslint.org/docs/rules/switch-colon-spacing
120-
"switch-colon-spacing": "error",
121103
// https://eslint.org/docs/rules/no-useless-computed-key
122104
"no-useless-computed-key": "error",
123-
// https://eslint.org/docs/rules/rest-spread-spacing
124-
"rest-spread-spacing": ["error"],
125105
// https://eslint.org/docs/rules/no-var
126106
"no-var": "error",
127107
// https://eslint.org/docs/rules/one-var
@@ -159,96 +139,11 @@ module.exports = {
159139
"no-implicit-coercion": "error",
160140
//https://eslint.org/docs/rules/no-unneeded-ternary
161141
"no-unneeded-ternary": "error",
162-
// https://eslint.org/docs/rules/semi
163-
"semi": ["error", "always"],
164-
// https://eslint.org/docs/rules/no-multi-spaces
165-
"no-multi-spaces": "error",
166-
// https://eslint.org/docs/rules/key-spacing
167-
"key-spacing": ["error", {
168-
"afterColon": true
169-
}],
170-
// https://eslint.org/docs/rules/keyword-spacing
171-
"keyword-spacing": ["error", {
172-
"before": true,
173-
"after": true
174-
}],
175-
// https://eslint.org/docs/rules/comma-spacing
176-
// Also requires one line code fix
177-
"comma-spacing": ["error", {
178-
"after": true
179-
}],
180-
//https://eslint.org/docs/rules/no-whitespace-before-property
181-
"no-whitespace-before-property": "error",
182-
// https://eslint.org/docs/rules/object-curly-newline
183-
"object-curly-newline": ["error", {
184-
"consistent": true,
185-
"multiline": true
186-
}],
187-
// https://eslint.org/docs/rules/object-property-newline
188-
"object-property-newline": "error",
189-
// https://eslint.org/docs/rules/brace-style
190-
"brace-style": "error",
191-
// https://eslint.org/docs/rules/no-multiple-empty-lines
192-
"no-multiple-empty-lines": ["error", {"max": 1}],
193-
// https://eslint.org/docs/rules/operator-linebreak
194-
"operator-linebreak": ["error", "before", {"overrides": {"=": "after"}}],
195-
// https://eslint.org/docs/rules/padding-line-between-statements
196-
"padding-line-between-statements": ["error", {
197-
"blankLine": "always",
198-
"prev": "multiline-block-like",
199-
"next": "*"
200-
}, {
201-
"blankLine": "always",
202-
"prev": "*",
203-
"next": "return"
204-
}],
205-
// https://eslint.org/docs/rules/space-infix-ops
206-
"space-infix-ops": "error",
207-
// https://eslint.org/docs/rules/space-unary-ops
208-
"space-unary-ops": ["error", {
209-
"words": true,
210-
"nonwords": false
211-
}],
212-
// https://eslint.org/docs/rules/arrow-spacing
213-
"arrow-spacing": "error",
214-
// https://eslint.org/docs/rules/semi-spacing
215-
"semi-spacing": ["error", {
216-
"before": false,
217-
"after": true
218-
}],
219-
220-
"vue/html-indent": [
221-
"error",
222-
4,
223-
{
224-
"attribute": 1,
225-
"baseIndent": 0,
226-
"closeBracket": 0,
227-
"alignAttributesVertically": true,
228-
"ignores": []
229-
}
230-
],
231-
"vue/html-self-closing": ["error",
232-
{
233-
"html": {
234-
"void": "never",
235-
"normal": "never",
236-
"component": "always"
237-
},
238-
"svg": "always",
239-
"math": "always"
240-
}
241-
],
242-
"vue/max-attributes-per-line": ["error", {
243-
"singleline": 1,
244-
"multiline": 1,
245-
}],
246142
"vue/first-attribute-linebreak": "error",
247143
"vue/multiline-html-element-content-newline": "off",
248144
"vue/singleline-html-element-content-newline": "off",
249145
"vue/multi-word-component-names": "off", // TODO enable, align with conventions
250146
"vue/no-mutating-props": "off"
251-
252147
},
253148
"overrides": [
254149
{

Diff for: .git-blame-ignore-revs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# git-blame ignored revisions
2+
# To configure, run:
3+
# git config blame.ignoreRevsFile .git-blame-ignore-revs
4+
# Requires Git > 2.23
5+
# See https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-fileltfilegt
6+

Diff for: .prettierignore

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Docs
2+
*.md
3+
4+
# Build output
5+
target
6+
dist
7+
8+
# Mac OS X Finder
9+
.DS_Store
10+
11+
# Node dependencies
12+
node_modules
13+
14+
# npm-debug log
15+
npm-debug.log
16+
17+
# karma reports
18+
report.*.json
19+
20+
# e2e test artifacts
21+
test-results
22+
html-test-results
23+
24+
# codecov artifacts
25+
.nyc_output
26+
coverage
27+
codecov

Diff for: .prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"trailingComma": "none",
3+
"singleQuote": true,
4+
"printWidth": 100
5+
}

Diff for: CONTRIBUTING.md

+26-12
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ The short version:
1818
for review.)
1919
4. Respond to any discussion. When the reviewer decides it's ready, they
2020
will merge back `master` and fill out their own check list.
21-
5. If you are a first-time contributor, please see [this discussion](https://github.com/nasa/openmct/discussions/3821) for further information.
21+
5. If you are a first-time contributor, please see [this discussion](https://github.com/nasa/openmct/discussions/3821) for further information.
2222

2323
## Contribution Process
2424

2525
Open MCT uses git for software version control, and for branching and
2626
merging. The central repository is at
27-
https://github.com/nasa/openmct.git.
27+
<https://github.com/nasa/openmct.git>.
2828

2929
### Roles
3030

@@ -116,6 +116,7 @@ the pull request containing the reviewer checklist (from below) and complete
116116
the merge back to the master branch.
117117

118118
Additionally:
119+
119120
* Every pull request must link to the issue that it addresses. Eg. “Addresses #1234” or “Closes #1234”. This is the responsibility of the pull request’s __author__. If no issue exists, [create one](https://github.com/nasa/openmct/issues/new/choose).
120121
* Every __author__ must include testing instructions. These instructions should identify the areas of code affected, and some minimal test steps. If addressing a bug, reproduction steps should be included, if they were not included in the original issue. If reproduction steps were included on the original issue, and are sufficient, refer to them.
121122
* A pull request that closes an issue should say so in the description. Including the text “Closes #1234” will cause the linked issue to be automatically closed when the pull request is merged. This is the responsibility of the pull request’s __author__.
@@ -132,25 +133,26 @@ changes.
132133

133134
### Code Standards
134135

135-
JavaScript sources in Open MCT must satisfy the ESLint rules defined in
136-
this repository. This is verified by the command line build.
136+
JavaScript sources in Open MCT must satisfy the [ESLint](https://eslint.org/) rules defined in
137+
this repository. [Prettier](https://prettier.io/) is used in conjunction with ESLint to enforce code style
138+
via automated formatting. These are verified by the command line build.
137139

138140
#### Code Guidelines
139141

140142
The following guidelines are provided for anyone contributing source code to the Open MCT project:
141143

142-
1. Write clean code. Here’s a good summary - https://github.com/ryanmcdermott/clean-code-javascript.
144+
1. Write clean code. Here’s a good summary - <https://github.com/ryanmcdermott/clean-code-javascript>.
143145
1. Include JSDoc for any exposed API (e.g. public methods, classes).
144146
1. Include non-JSDoc comments as-needed for explaining private variables,
145-
methods, or algorithms when they are non-obvious. Otherwise code
147+
methods, or algorithms when they are non-obvious. Otherwise code
146148
should be self-documenting.
147149
1. Classes and Vue components should use camel case, first letter capitalized
148150
(e.g. SomeClassName).
149151
1. Methods, variables, fields, events, and function names should use camelCase,
150152
first letter lower-case (e.g. someVariableName).
151153
1. Source files that export functions should use camelCase, first letter lower-case (eg. testTools.js)
152-
1. Constants (variables or fields which are meant to be declared and
153-
initialized statically, and never changed) should use only capital
154+
1. Constants (variables or fields which are meant to be declared and
155+
initialized statically, and never changed) should use only capital
154156
letters, with underscores between words (e.g. SOME_CONSTANT). They should always be declared as `const`s
155157
1. File names should be the name of the exported class, plus a .js extension
156158
(e.g. SomeClassName.js).
@@ -159,21 +161,25 @@ The following guidelines are provided for anyone contributing source code to the
159161
(e.g. as arguments to a forEach call). Anonymous functions should always be arrow functions.
160162
1. Named functions are preferred over functions assigned to variables.
161163
eg.
164+
162165
```JavaScript
163166
function renameObject(object, newName) {
164167
Object.name = newName;
165168
}
166169
```
170+
167171
is preferable to
172+
168173
```JavaScript
169174
const rename = (object, newName) => {
170175
Object.name = newName;
171176
}
172177
```
178+
173179
1. Avoid deep nesting (especially of functions), except where necessary
174180
(e.g. due to closure scope).
175181
1. End with a single new-line character.
176-
1. Always use ES6 `Class`es and inheritance rather than the pre-ES6 prototypal
182+
1. Always use ES6 `Class`es and inheritance rather than the pre-ES6 prototypal
177183
pattern.
178184
1. Within a given function's scope, do not mix declarations and imperative
179185
code, and present these in the following order:
@@ -182,19 +188,24 @@ The following guidelines are provided for anyone contributing source code to the
182188
* Finally, the returned value. A single return statement at the end of the function should be used, except where an early return would improve code clarity.
183189
1. Avoid the use of "magic" values.
184190
eg.
191+
185192
```JavaScript
186193
const UNAUTHORIZED = 401;
187194
if (responseCode === UNAUTHORIZED)
188195
```
196+
189197
is preferable to
198+
190199
```JavaScript
191200
if (responseCode === 401)
192201
```
202+
193203
1. Use the ternary operator only for simple cases such as variable assignment. Nested ternaries should be avoided in all cases.
194204
1. Unit Test specs should reside alongside the source code they test, not in a separate directory.
195205
1. Organize code by feature, not by type.
196206
eg.
197-
```
207+
208+
```txt
198209
- telemetryTable
199210
- row
200211
TableRow.js
@@ -206,8 +217,10 @@ The following guidelines are provided for anyone contributing source code to the
206217
plugin.js
207218
pluginSpec.js
208219
```
220+
209221
is preferable to
210-
```
222+
223+
```txt
211224
- telemetryTable
212225
- components
213226
TableRow.vue
@@ -219,6 +232,7 @@ The following guidelines are provided for anyone contributing source code to the
219232
plugin.js
220233
pluginSpec.js
221234
```
235+
222236
Deviations from Open MCT code style guidelines require two-party agreement,
223237
typically from the author of the change and its reviewer.
224238

@@ -257,7 +271,7 @@ these standards.
257271

258272
## Issue Reporting
259273

260-
Issues are tracked at https://github.com/nasa/openmct/issues.
274+
Issues are tracked at <https://github.com/nasa/openmct/issues>.
261275

262276
Issue severity is categorized as follows (in ascending order):
263277

Diff for: e2e/helper/faultUtils.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
* this source code distribution or the Licensing information page available
2020
* at runtime from the About dialog for additional information.
2121
*****************************************************************************/
22-
22+
/* global __dirname */
2323
const path = require('path');
2424

2525
/**
2626
* @param {import('@playwright/test').Page} page
2727
*/
2828
async function navigateToFaultManagementWithExample(page) {
29-
// eslint-disable-next-line no-undef
3029
await page.addInitScript({ path: path.join(__dirname, './', 'addInitExampleFaultProvider.js') });
3130

3231
await navigateToFaultItemInTree(page);
@@ -36,7 +35,6 @@ async function navigateToFaultManagementWithExample(page) {
3635
* @param {import('@playwright/test').Page} page
3736
*/
3837
async function navigateToFaultManagementWithStaticExample(page) {
39-
// eslint-disable-next-line no-undef
4038
await page.addInitScript({ path: path.join(__dirname, './', 'addInitExampleFaultProviderStatic.js') });
4139

4240
await navigateToFaultItemInTree(page);
@@ -46,7 +44,6 @@ async function navigateToFaultManagementWithStaticExample(page) {
4644
* @param {import('@playwright/test').Page} page
4745
*/
4846
async function navigateToFaultManagementWithoutExample(page) {
49-
// eslint-disable-next-line no-undef
5047
await page.addInitScript({ path: path.join(__dirname, './', 'addInitFaultManagementPlugin.js') });
5148

5249
await navigateToFaultItemInTree(page);

0 commit comments

Comments
 (0)