Skip to content

Commit

Permalink
Merge pull request #11754 from hashicorp/b-ui/fix-linter
Browse files Browse the repository at this point in the history
ui:  fix linter and prettier
  • Loading branch information
ChaiWithJai authored Jan 24, 2022
2 parents 1471de4 + a6b3836 commit 81f7d7d
Show file tree
Hide file tree
Showing 427 changed files with 9,042 additions and 4,458 deletions.
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

0 comments on commit 81f7d7d

Please sign in to comment.