Skip to content

Commit

Permalink
Merge pull request #535 from navikt/LWSLinting
Browse files Browse the repository at this point in the history
Lws linting
  • Loading branch information
EirikFladby authored Feb 2, 2024
2 parents 33e68ec + 1f92c7d commit ed19137
Show file tree
Hide file tree
Showing 27 changed files with 19,140 additions and 16,367 deletions.
42 changes: 39 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,46 @@
"browser": true,
"es2021": true
},
"extends": "eslint:recommended",
"extends": [
"eslint:recommended",
"@salesforce/eslint-config-lwc/recommended",
"@salesforce/eslint-config-lwc/i18n",
"@locker/eslint-config-locker/recommended",
"plugin:@salesforce/eslint-plugin-aura/recommended",
"plugin:@salesforce/eslint-plugin-aura/locker"
],
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
"sourceType": "module",
"requireConfigFile": false,
"babelOptions": {
"parserOpts": {
"plugins": ["classProperties", ["decorators", { "decoratorsBeforeExport": false }]]
}
}
},
"rules": {}
"rules": {
"no-console": "off",
"@salesforce/lightning/prefer-i18n-service": "off"
},
"plugins": ["@lwc/eslint-plugin-lwc", "@salesforce/eslint-plugin-aura"],
// Based on this discussion https://github.com/forcedotcom/eslint-plugin-aura/issues/8 which resulted in this file
// https://github.com/forcedotcom/salesforcedx-templates/blob/main/src/templates/project/aura.eslintrc.json
"overrides": [
{
"files": ["**/aura/**"],
"rules": { "vars-on-top": "off", "no-unused-expressions": "off" }
},
// Based on this file https://github.com/forcedotcom/salesforcedx-templates/blob/main/src/templates/project/lwc.eslintrc.json
{
"files": ["*.test.js"],
"rules": {
"@lwc/lwc/no-unexpected-wire-adapter-usages": "off"
},
"env": {
"node": true
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export default class FlowCombobox extends LightningElement {
}
}
}
return null;
}

@wire(getObjectInfo, { objectApiName: '$_selectedObjectType' })
Expand Down Expand Up @@ -247,7 +248,6 @@ export default class FlowCombobox extends LightningElement {

generateMergeFieldsFromBuilderContext(builderContext) {
let optionsByType = {};
let key = 0;

this.getTypes().forEach((curType) => {
let typeParts = curType.split('.');
Expand Down Expand Up @@ -359,21 +359,19 @@ export default class FlowCombobox extends LightningElement {
}

isCollection(curObject, isCollectionField) {
if (curObject.hasOwnProperty(isCollectionField)) {
if (Object.prototype.hasOwnProperty.call(curObject, isCollectionField)) {
return curObject[isCollectionField];
} else {
return curObject[flowComboboxDefaults.isCollectionField];
}
return curObject[flowComboboxDefaults.isCollectionField];
}

getTypeByDescriptor(curObjectFieldType, typeDescriptor) {
if (!typeDescriptor) {
return flowComboboxDefaults.stringDataType;
} else if (typeDescriptor.apiName === flowComboboxDefaults.recordLookupsType) {
return flowComboboxDefaults.dataTypeSObject;
} else {
return curObjectFieldType ? curObjectFieldType : flowComboboxDefaults.stringDataType;
}
return curObjectFieldType ? curObjectFieldType : flowComboboxDefaults.stringDataType;
}

generateOptionLine(type, label, value, isCollection, objectType, optionIcon, isObject, displayType, key, flowType) {
Expand Down Expand Up @@ -431,7 +429,7 @@ export default class FlowCombobox extends LightningElement {
this.dispatchEvent(valueChangedEvent);
}

resetData(event) {
resetData() {
this.value = '';
this.resetTypeOptions();
this.closeOptionDialog();
Expand All @@ -445,7 +443,7 @@ export default class FlowCombobox extends LightningElement {
this.setOptions(this._mergeFields);
}

openOptionDialog(event) {
openOptionDialog() {
// this.isDataSelected = false;
this.isMenuOpen = true;
this.dropdownClass = 'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open';
Expand Down Expand Up @@ -554,7 +552,7 @@ export default class FlowCombobox extends LightningElement {
return this.iconsPerType[variableType];
}

handleOpenOptions(event) {
handleOpenOptions() {
// event.stopPropagation();
console.log('handleOpenOptions');
this.selfEvent = true;
Expand All @@ -571,7 +569,7 @@ export default class FlowCombobox extends LightningElement {
this.handleOpenOptions(event);
}

handleCloseOptions(event) {
handleCloseOptions() {
this.closeOptionDialog();
}

Expand Down Expand Up @@ -599,7 +597,7 @@ export default class FlowCombobox extends LightningElement {
}
}

toggleMenu(event) {
toggleMenu() {
if (this.isMenuOpen) {
this.closeOptionDialog(true);
} else {
Expand Down Expand Up @@ -642,6 +640,7 @@ export default class FlowCombobox extends LightningElement {
if (this.maxWidth) {
return 'max-width: ' + this.maxWidth + 'px;';
}
return null;
}

@api
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export { flowComboboxDefaults, isReference, formattedValue, getDataType, removeFormatting };

const flowComboboxDefaults = {
stringDataType: 'String',
referenceDataType: 'reference',
Expand All @@ -20,17 +18,15 @@ const isReference = (value) => {
const getDataType = (currentText) => {
if (isReference(currentText)) {
return flowComboboxDefaults.referenceDataType;
} else {
return flowComboboxDefaults.stringDataType;
}
return flowComboboxDefaults.stringDataType;
};

const formattedValue = (value, dataType) => {
if (isReference(value)) {
return value;
} else {
return dataType === flowComboboxDefaults.referenceDataType ? '{!' + value + '}' : value;
}
return dataType === flowComboboxDefaults.referenceDataType ? '{!' + value + '}' : value;
};

const removeFormatting = (value) => {
Expand All @@ -41,3 +37,5 @@ const removeFormatting = (value) => {
let clearValue = isRef ? value.substring(0, value.lastIndexOf('}')).replace('{!', '') : value;
return clearValue;
};

export { flowComboboxDefaults, isReference, formattedValue, getDataType, removeFormatting };
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default class fbc_pickObjectAndField extends LightningElement {
} else if (data) {
let fields = data.fields;
let fieldResults = [];
// eslint-disable-next-line guard-for-in
for (let field in (this.fields = fields)) {
if (Object.prototype.hasOwnProperty.call(fields, field)) {
if (this.isTypeSupported(fields[field])) {
Expand Down Expand Up @@ -102,7 +103,7 @@ export default class fbc_pickObjectAndField extends LightningElement {
this.fields = fieldResults;
if (this.fields) {
this.dispatchDataChangedEvent({
...this.fields.find((curField) => curField.value == this._field),
...this.fields.find((curField) => curField.value === this._field),
...{ isInit: true }
});
}
Expand Down Expand Up @@ -141,9 +142,8 @@ export default class fbc_pickObjectAndField extends LightningElement {
get availableObjectTypesList() {
if (this.availableObjectTypes) {
return this.splitValues(this.availableObjectTypes.toLowerCase());
} else {
return [];
}
return [];
}

get isError() {
Expand All @@ -165,11 +165,10 @@ export default class fbc_pickObjectAndField extends LightningElement {

get fieldType() {
if (this.fields && this._field) {
let foundField = this.fields.find((e) => e.value == this._field);
let foundField = this.fields.find((e) => e.value === this._field);
return foundField ? foundField.dataType : null;
} else {
return null;
}
return null;
}

handleObjectChange(event) {
Expand All @@ -183,7 +182,7 @@ export default class fbc_pickObjectAndField extends LightningElement {

handleFieldChange(event) {
this._field = event.detail.value;
this.dispatchDataChangedEvent(this.fields.find((curField) => curField.value == this._field));
this.dispatchDataChangedEvent(this.fields.find((curField) => curField.value === this._field));
const attributeChangeEvent = new FlowAttributeChangeEvent('field', this._field);
this.dispatchEvent(attributeChangeEvent);
}
Expand All @@ -206,9 +205,8 @@ export default class fbc_pickObjectAndField extends LightningElement {
splitValues(originalString) {
if (originalString) {
return originalString.replace(/ /g, '').split(',');
} else {
return [];
}
return [];
}

get renderFlowCombobox() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { standardObjectOptions };
const standardObjectOptions = [
{ value: 'Account', label: 'Account' },
{ value: 'AccountPartner', label: 'Account Partner' },
Expand Down Expand Up @@ -56,3 +55,4 @@ const standardObjectOptions = [
{ value: 'WorkOrderLineItem', label: 'Work Order Line Item' },
{ value: 'WorkType', label: 'Work Type' }
];
export { standardObjectOptions };
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export default class QuickChoiceCpe extends LightningElement {
);
}

initializeValues(value) {
initializeValues() {
if (this._values && this._values.length) {
this._values.forEach((curInputParam) => {
if (curInputParam.name && this.inputValues[curInputParam.name]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,18 @@ export default class QuickChoiceFSC extends LightningElement {

doSort(value, sortFlag) {
if (!value) {
return;
return null;
}
if (!sortFlag) {
return value;
}
let fieldValue = (row) => row['label'] || '';
let fieldValue = (row) => row.label || '';
return [
...value.sort(
(a, b) => ((a = fieldValue(a).toUpperCase()), (b = fieldValue(b).toUpperCase()), (a > b) - (b > a))
)
...value.sort((a, b) => {
a = fieldValue(a).toUpperCase();
b = fieldValue(b).toUpperCase();
return (a > b) - (b > a);
})
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
({
closeModal: function (component, event, helper) {
closeModal: function (component) {
component.set('v.showPanel', false);
},

handleToolbarAction: function (component, event, helper) {
handleToolbarAction: function (component, event) {
const flowName = event.getParam('flowName');
const flowInputs = event.getParam('flowInputs');
component.set('v.showPanel', true);
Expand All @@ -19,7 +19,7 @@
}
},

handleModalKey: function (component, event, helper) {
handleModalKey: function (component, event) {
if (event.keyCode === 27 || event.code === 'Escape') {
var action = component.get('c.closeModal');
$A.enqueueAction(action);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
({
// Your renderer method overrides go here
rerender: function (cmp, helper) {
rerender: function (cmp) {
this.superRerender();
// do custom rerendering here
const modal = cmp.find('firstfocusable');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
({
invoke: function (component, event, helper) {
invoke: function (component) {
let workspaceAPI = component.find('workspace');
workspaceAPI
.getFocusedTabInfo()
.then((tabInfo) => {
workspaceAPI
.closeTab({ tabId: tabInfo.tabId })
.then((response) => {
.then(() => {
//Success
})
.catch((error) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
({
myAction : function(component, event, helper) {

}
})
myAction: function () {}
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
({
invoke: function (component, event, helper) {
invoke: function (component) {
var omniAPI = component.find('omniToolkit');
omniAPI
.logout()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export default class CommunityConversationNoteRelatedItem extends NavigationMixi
return (
' fra ' + new Intl.DateTimeFormat('no-no', { dateStyle: 'long', timeStyle: 'short' }).format(fullDate)
);
} else {
}
return '';
}

}

get label() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ export default class CommunityExpandablePanel extends LightningElement {
expand.style.height = 'auto';
let boundingRect = expand.getBoundingClientRect();
expand.style.height = '0px';
// eslint-disable-next-line @lwc/lwc/no-async-operation
window.requestAnimationFrame(function () {
expand.style.height = boundingRect.height + 'px';
});
// eslint-disable-next-line @lwc/lwc/no-async-operation, @locker/locker/distorted-window-set-timeout
setTimeout(() => {
if (this.showpanel) {
expand.style.height = 'auto';
Expand All @@ -40,9 +42,11 @@ export default class CommunityExpandablePanel extends LightningElement {
} else {
let boundingRect = expand.getBoundingClientRect();
expand.style.height = boundingRect.height + 'px';
// eslint-disable-next-line @lwc/lwc/no-async-operation
window.requestAnimationFrame(function () {
expand.style.height = '0px';
});
// eslint-disable-next-line @lwc/lwc/no-async-operation, @locker/locker/distorted-window-set-timeout
setTimeout(() => {
wrapper.display = 'none';
}, 250);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class CommunityLanguageSelector extends LightningElement {
];

handlePicklist(event) {
if (event.detail != 'PLACEHOLDER') {
if (event.detail !== 'PLACEHOLDER') {
setLanguage({ language: event.detail }).then((result) => {
console.log(result);
window.location.reload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class CommunityRedirectError extends NavigationMixin(LightningEle
}
} // Replaces the current page in your browser history with the URL
).then((generatedUrl) => {
// eslint-disable-next-line @locker/locker/distorted-xml-http-request-window-open
window.open(generatedUrl, '_self');
});
}
Expand Down
Loading

0 comments on commit ed19137

Please sign in to comment.