Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: fix linter and prettier #11754

Merged
merged 20 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
28b64b8
chore: add jsconfig to stop experimental decorator warnings
ChaiWithJai Dec 28, 2021
dc31860
ui: match linting and prettier packages with ember-new-output 3.24
ChaiWithJai Dec 28, 2021
c4882b6
ui: match eslintrc with ember-new-output
ChaiWithJai Dec 28, 2021
3c78be7
ui: ignore cache for eslint, to speed up linting
ChaiWithJai Dec 28, 2021
ba92ba3
ui: match eslint script with ember-new-output
ChaiWithJai Dec 28, 2021
d0f8322
ui: fix auto-fixable linting errors
ChaiWithJai Dec 28, 2021
4fe64bb
ui: turn off no-class-classes rule
ChaiWithJai Dec 28, 2021
acb8185
ui: turn off no-computed-properties-in-native-classes
ChaiWithJai Dec 28, 2021
720bfa8
ui: disable linting on files that use controllerFor
ChaiWithJai Dec 28, 2021
d8faa5e
ui: replace this.render with render test-helper in tests
ChaiWithJai Dec 28, 2021
2701de5
ui: storybook accesses private routing service
ChaiWithJai Dec 28, 2021
56d24d8
ui: turn off no-classic-components
ChaiWithJai Dec 28, 2021
1975f43
ui: turn off no-component-lifecycle-hooks
ChaiWithJai Dec 28, 2021
e540aa3
ui: turn off tagless components linting error
ChaiWithJai Dec 28, 2021
ba9d95c
ui: disable no-string-protype-extensions where its currently in use
ChaiWithJai Dec 28, 2021
635e937
ui: upgrade prettier to match 3.28 ember-new-output
ChaiWithJai Dec 28, 2021
8c600ac
ui: prettify js files
ChaiWithJai Dec 28, 2021
2032813
ui: apply new qunit linting rules to tests
ChaiWithJai Dec 28, 2021
cae4bec
ui: fix remaining linting errors
ChaiWithJai Jan 20, 2022
a6b3836
fix: mirage fixtures are randomized so we cant assert.expect
ChaiWithJai Jan 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ rkt-*

# misc
/ui/.sass-cache
/ui/.eslintcache
/ui/.storybook/preview-head.html
/ui/connect.lock
/ui/coverage/*
Expand Down
49 changes: 22 additions & 27 deletions ui/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,50 @@

module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true,
},
},
globals: {
server: true,
},
env: {
browser: true,
es6: true,
},
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
],
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true,
},
},
plugins: [
'ember'
'plugin:prettier/recommended',
],
rules: {
indent: ['error', 2, { SwitchCase: 1 }],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single', 'avoid-escape'],
semi: ['error', 'always'],
'no-constant-condition': [
'error',
{
checkLoops: false,
},
],
'ember/classic-decorator-hooks': 'error',
'ember/classic-decorator-no-classic-methods': 'error',
'ember/no-get': 'off',
'ember/no-mixins': 'off',
'ember/no-classic-classes': 'off',
'ember/no-computed-properties-in-native-classes': 'off',
'ember/no-classic-components': 'off',
'ember/no-component-lifecycle-hooks': 'off',
'ember/require-tagless-components': 'off',
},
overrides: [
// node files
{
files: [
'.eslintrc.js',
'.prettierrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
'server/**/*.js',
'lib/*/index.js',
'server/**/*.js',
],
parserOptions: {
sourceType: 'script',
Expand All @@ -61,14 +55,15 @@ module.exports = {
node: true,
},
plugins: ['node'],
extends: ['plugin:node/recommended'],
rules: {
'node/no-unpublished-require': 'off'
// this can be removed once the following is fixed
// https://github.com/mysticatea/eslint-plugin-node/issues/77
'node/no-unpublished-require': 'off',
},
},
{
files: [
'stories/**/*.js'
],
files: ['stories/**/*.js'],
parserOptions: {
sourceType: 'module',
},
Expand Down
21 changes: 21 additions & 0 deletions ui/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*
.eslintcache

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
2 changes: 0 additions & 2 deletions ui/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"printWidth": 100,
"singleQuote": true,
"trailingComma": "es5",
"overrides": [
{
"files": "*.hbs",
Expand Down
5 changes: 5 additions & 0 deletions ui/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
singleQuote: true,
};
11 changes: 9 additions & 2 deletions ui/.storybook/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ module.exports = {
shippedProposals: true,
useBuiltIns: 'usage',
corejs: '3',
targets: ['last 1 Chrome versions', 'last 1 Firefox versions', 'last 1 Safari versions'],
targets: [
'last 1 Chrome versions',
'last 1 Firefox versions',
'last 1 Safari versions',
],
},
],
],
Expand All @@ -27,7 +31,10 @@ module.exports = {
],
['@babel/plugin-proposal-class-properties', { loose: true }],
'@babel/plugin-syntax-dynamic-import',
['@babel/plugin-proposal-object-rest-spread', { loose: true, useBuiltIns: true }],
[
'@babel/plugin-proposal-object-rest-spread',
{ loose: true, useBuiltIns: true },
],
'babel-plugin-macros',
['emotion', { sourceMap: true, autoLabel: true }],
[
Expand Down
2 changes: 1 addition & 1 deletion ui/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ addParameters({
},
});

addDecorator(storyFn => {
addDecorator((storyFn) => {
let { template, context } = storyFn();

let wrapperElementStyle = {
Expand Down
3 changes: 2 additions & 1 deletion ui/.storybook/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export default create({

// Typography
// From variables.scss
fontBase: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif",
fontBase:
"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif",
// From Bulma
fontCode: 'monospace',

Expand Down
2 changes: 1 addition & 1 deletion ui/.storybook/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-env node */
module.exports = function({ config }) {
module.exports = function ({ config }) {
config.module.rules.push({
test: /\.stories\.jsx?$/,
loaders: [require.resolve('@storybook/source-loader')],
Expand Down
52 changes: 35 additions & 17 deletions ui/app/abilities/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,44 @@ export default class Abstract extends Ability {
get rulesForNamespace() {
let namespace = this._namespace;

return (this.get('token.selfTokenPolicies') || []).toArray().reduce((rules, policy) => {
let policyNamespaces = get(policy, 'rulesJSON.Namespaces') || [];

let matchingNamespace = this._findMatchingNamespace(policyNamespaces, namespace);

if (matchingNamespace) {
rules.push(policyNamespaces.find(namespace => namespace.Name === matchingNamespace));
}
return (this.get('token.selfTokenPolicies') || [])
.toArray()
.reduce((rules, policy) => {
let policyNamespaces = get(policy, 'rulesJSON.Namespaces') || [];

let matchingNamespace = this._findMatchingNamespace(
policyNamespaces,
namespace
);

if (matchingNamespace) {
rules.push(
policyNamespaces.find(
(namespace) => namespace.Name === matchingNamespace
)
);
}

return rules;
}, []);
return rules;
}, []);
}

@computed('token.selfTokenPolicies.[]')
get capabilitiesForAllNamespaces() {
return (this.get('token.selfTokenPolicies') || [])
.toArray()
.reduce((allCapabilities, policy) => {
(get(policy, 'rulesJSON.Namespaces') || []).forEach(({ Capabilities }) => {
allCapabilities = allCapabilities.concat(Capabilities);
});
(get(policy, 'rulesJSON.Namespaces') || []).forEach(
({ Capabilities }) => {
allCapabilities = allCapabilities.concat(Capabilities);
}
);
return allCapabilities;
}, []);
}

namespaceIncludesCapability(capability) {
return this.rulesForNamespace.some(rules => {
return this.rulesForNamespace.some((rules) => {
let capabilities = get(rules, 'Capabilities') || [];
return capabilities.includes(capability);
});
Expand All @@ -76,12 +87,16 @@ export default class Abstract extends Ability {
return namespace;
}

let globNamespaceNames = namespaceNames.filter(namespaceName => namespaceName.includes('*'));
let globNamespaceNames = namespaceNames.filter((namespaceName) =>
namespaceName.includes('*')
);

let matchingNamespaceName = globNamespaceNames.reduce(
(mostMatching, namespaceName) => {
// Convert * wildcards to .* for regex matching
let namespaceNameRegExp = new RegExp(namespaceName.replace(/\*/g, '.*'));
let namespaceNameRegExp = new RegExp(
namespaceName.replace(/\*/g, '.*')
);
let characterDifference = namespace.length - namespaceName.length;

if (
Expand All @@ -96,7 +111,10 @@ export default class Abstract extends Ability {
return mostMatching;
}
},
{ mostMatchingNamespaceName: null, mostMatchingCharacterDifference: Number.MAX_SAFE_INTEGER }
{
mostMatchingNamespaceName: null,
mostMatchingCharacterDifference: Number.MAX_SAFE_INTEGER,
}
).mostMatchingNamespaceName;

if (matchingNamespaceName) {
Expand Down
10 changes: 7 additions & 3 deletions ui/app/abilities/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ import { computed, get } from '@ember/object';
import { or } from '@ember/object/computed';

export default class Client extends AbstractAbility {
@or('bypassAuthorization', 'selfTokenIsManagement', 'policiesIncludeAgentReadOrWrite')
@or(
'bypassAuthorization',
'selfTokenIsManagement',
'policiesIncludeAgentReadOrWrite'
)
canRead;

@computed('token.selfTokenPolicies.[]')
get policiesIncludeAgentReadOrWrite() {
const policies = (get(this, 'token.selfTokenPolicies') || [])
.toArray()
.map(policy => get(policy, 'rulesJSON.Agent.Policy'))
.map((policy) => get(policy, 'rulesJSON.Agent.Policy'))
.compact();

return policies.some(policy => policy === 'read' || policy === 'write');
return policies.some((policy) => policy === 'read' || policy === 'write');
}
}
2 changes: 1 addition & 1 deletion ui/app/abilities/allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class Allocation extends AbstractAbility {

@computed('[email protected]')
get policiesSupportExec() {
return this.rulesForNamespace.some(rules => {
return this.rulesForNamespace.some((rules) => {
let capabilities = get(rules, 'Capabilities') || [];
return capabilities.includes('alloc-exec');
});
Expand Down
19 changes: 14 additions & 5 deletions ui/app/abilities/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,36 @@ export default class Client extends AbstractAbility {
@or('bypassAuthorization', 'selfTokenIsManagement', 'policiesIncludeNodeRead')
canRead;

@or('bypassAuthorization', 'selfTokenIsManagement', 'policiesIncludeNodeWrite')
@or(
'bypassAuthorization',
'selfTokenIsManagement',
'policiesIncludeNodeWrite'
)
canWrite;

@computed('token.selfTokenPolicies.[]')
get policiesIncludeNodeRead() {
return policiesIncludePermissions(this.get('token.selfTokenPolicies'), ['read', 'write']);
return policiesIncludePermissions(this.get('token.selfTokenPolicies'), [
'read',
'write',
]);
}

@computed('token.selfTokenPolicies.[]')
get policiesIncludeNodeWrite() {
return policiesIncludePermissions(this.get('token.selfTokenPolicies'), ['write']);
return policiesIncludePermissions(this.get('token.selfTokenPolicies'), [
'write',
]);
}
}

function policiesIncludePermissions(policies = [], permissions = []) {
// For each policy record, extract the Node policy
const nodePolicies = policies
.toArray()
.map(policy => get(policy, 'rulesJSON.Node.Policy'))
.map((policy) => get(policy, 'rulesJSON.Node.Policy'))
.compact();

// Check for requested permissions
return nodePolicies.some(policy => permissions.includes(policy));
return nodePolicies.some((policy) => permissions.includes(policy));
}
6 changes: 5 additions & 1 deletion ui/app/abilities/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export default class Job extends AbstractAbility {
@or('bypassAuthorization', 'selfTokenIsManagement')
canListAll;

@or('bypassAuthorization', 'selfTokenIsManagement', 'policiesSupportDispatching')
@or(
'bypassAuthorization',
'selfTokenIsManagement',
'policiesSupportDispatching'
)
canDispatch;

@computed('[email protected]')
Expand Down
6 changes: 5 additions & 1 deletion ui/app/abilities/recommendation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ export default class Recommendation extends AbstractAbility {
@and('dynamicApplicationSizingIsPresent', 'hasPermissions')
canAccept;

@or('bypassAuthorization', 'selfTokenIsManagement', 'policiesSupportAcceptingOnAnyNamespace')
@or(
'bypassAuthorization',
'selfTokenIsManagement',
'policiesSupportAcceptingOnAnyNamespace'
)
hasPermissions;

@computed('capabilitiesForAllNamespaces.[]')
Expand Down
Loading