Skip to content

Commit 789d960

Browse files
authored
Merge pull request #22 from sfdctaka/disableLintForBundle
Disable lint for bundle when eslint-disable is used
2 parents 3fdf9a6 + 2343877 commit 789d960

File tree

6 files changed

+244
-4
lines changed

6 files changed

+244
-4
lines changed

lib/processor.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,13 @@ function preprocess(text, filename) {
8989
// then it will use the report instead rather than trying to run Komaci analysis again.
9090
addReport(filename, eslintReports);
9191

92-
// Have at least one fake item in the array so that eslint will continue its process further.
93-
return [{ text: '', filename }];
92+
// Continue linting the text only for Javascript. For html, further linting cannot be
93+
// performed by eslint so pass empty string.
94+
if (ext === '.html') {
95+
return [{ text: '', filename }];
96+
} else {
97+
return [{ text: text, filename }];
98+
}
9499
}
95100
}
96101

lib/util/helper.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function rangeToLoc(range) {
2121
return {
2222
start: {
2323
// Komaci reports line number using 0 based index so adjust it by 1.
24-
// GUS ticket: https://gus.lightning.force.com/lightning/r/ADM_Work__c/a07EE00000uV9xtYAC/view
2524
line: line + 1,
2625
column: column
2726
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@salesforce/eslint-plugin-lwc-graph-analyzer",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"description": "ESLint plugin to analyze data graph in a LWC component",
55
"contributors": [
66
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2023, salesforce.com, inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: MIT
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6+
*/
7+
8+
'use strict';
9+
10+
const { assert } = require('chai');
11+
const { lintBundle } = require('../helper');
12+
13+
describe('Bundle linting', function () {
14+
it('should return correct errors', function () {
15+
const messages = lintBundle(__filename, 'test.js');
16+
17+
// All lint warnings are suppressed using variants of eslint-disable
18+
assert.equal(messages.length, 0);
19+
});
20+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<template>
2+
<h1>File Upload</h1>
3+
4+
<div>
5+
<lightning-input
6+
type="file"
7+
name="fileUploader"
8+
label="Pick file to upload"
9+
multiple="true"
10+
accept="*/*"
11+
onchange={handleInputChange}
12+
>
13+
</lightning-input>
14+
</div>
15+
16+
<!-- Currently komaci only supports the if:true= instead of the new lwc:if directive -->
17+
<div if:true={fileName}>
18+
<p>Selected file:</p>
19+
<p>{fileName}</p>
20+
<div class="inputs">
21+
<lightning-input
22+
type="text"
23+
label="Title"
24+
value={titleValue}
25+
onchange={handleTitleInputChange}
26+
></lightning-input>
27+
<lightning-input
28+
type="text"
29+
label="Description"
30+
value={descriptionValue}
31+
onchange={handleDescriptionInputChange}
32+
></lightning-input>
33+
</div>
34+
<button
35+
class="slds-button slds-button_brand slds-var-m-top_medium"
36+
disabled={uploadingFile}
37+
onclick={handleUploadClick}
38+
>
39+
Upload
40+
</button>
41+
</div>
42+
43+
<!-- Currently komaci only supports the if:true= instead of the new lwc:if directive -->
44+
<div if:true={errorMessage}>
45+
<lightning-card title="Error">
46+
<div class="card-body">{errorMessage}</div>
47+
</lightning-card>
48+
</div>
49+
</template>
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import { LightningElement, api, track, wire } from 'lwc';
2+
import { unstable_createContentDocumentAndVersion, createRecord } from 'lightning/uiRecordApi';
3+
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
4+
5+
export default class FileUpload extends LightningElement {
6+
@api
7+
recordId;
8+
9+
@track
10+
files = undefined;
11+
12+
@track
13+
uploadingFile = false;
14+
15+
@track
16+
titleValue = '';
17+
18+
@track
19+
descriptionValue = '';
20+
21+
@track
22+
errorMessage = '';
23+
24+
get recordId() {
25+
return recordId;
26+
}
27+
28+
/* eslint-disable */
29+
get fileName() {
30+
const file = this.files && this.files[0];
31+
if (file) {
32+
return file.name;
33+
}
34+
return undefined;
35+
}
36+
/* eslint-enable */
37+
38+
/* eslint-disable no-getter-contains-more-than-return-statement */
39+
get fileName1() {
40+
const file = this.files && this.files[0];
41+
if (file) {
42+
return file.name;
43+
}
44+
return undefined;
45+
}
46+
/* eslint-enable no-getter-contains-more-than-return-statement */
47+
48+
// eslint-disable-next-line
49+
get fileName2() {
50+
const file = this.files && this.files[0];
51+
if (file) {
52+
return file.name;
53+
}
54+
return undefined;
55+
}
56+
57+
// eslint-disable-next-line no-getter-contains-more-than-return-statement
58+
get fileName3() {
59+
const file = this.files && this.files[0];
60+
if (file) {
61+
return file.name;
62+
}
63+
return undefined;
64+
}
65+
66+
// prettier-ignore
67+
get fileName4() { // eslint-disable-line
68+
const file = this.files && this.files[0];
69+
if (file) {
70+
return file.name;
71+
}
72+
return undefined;
73+
}
74+
75+
// prettier-ignore
76+
get fileName5() { // eslint-disable-line no-getter-contains-more-than-return-statement
77+
const file = this.files && this.files[0];
78+
if (file) {
79+
return file.name;
80+
}
81+
return undefined;
82+
}
83+
84+
handleInputChange(event) {
85+
this.files = event.detail.files;
86+
this.titleValue = this.fileName;
87+
}
88+
89+
handleTitleInputChange(event) {
90+
this.titleValue = event.detail.value;
91+
}
92+
93+
handleDescriptionInputChange(event) {
94+
this.descriptionValue = event.detail.value;
95+
}
96+
97+
resetInputs() {
98+
this.files = [];
99+
this.titleValue = '';
100+
this.descriptionValue = '';
101+
this.errorMessage = '';
102+
}
103+
104+
// Handle the user uploading a file
105+
async handleUploadClick() {
106+
if (this.uploadingFile) {
107+
return;
108+
}
109+
110+
const file = this.files && this.files[0];
111+
if (!file) {
112+
return;
113+
}
114+
115+
try {
116+
this.uploadingFile = true;
117+
118+
// Create a ContentDocumentLink (CDL) to associate the uploaded file
119+
// to the Files Related List of a record, like a Work Order.
120+
const contentDocumentAndVersion = await unstable_createContentDocumentAndVersion({
121+
title: this.titleValue,
122+
description: this.descriptionValue,
123+
fileData: file
124+
});
125+
126+
if (this.recordId) {
127+
const contentDocumentId = contentDocumentAndVersion.contentDocument.id;
128+
await this.createCdl(this.recordId, contentDocumentId);
129+
}
130+
this.resetInputs();
131+
} catch (error) {
132+
console.error(error);
133+
this.errorMessage = error;
134+
} finally {
135+
this.uploadingFile = false;
136+
}
137+
}
138+
139+
async createCdl(recordId, contentDocumentId) {
140+
return createRecord({
141+
apiName: 'ContentDocumentLink',
142+
fields: {
143+
LinkedEntityId: recordId,
144+
ContentDocumentId: contentDocumentId,
145+
ShareType: 'V'
146+
}
147+
})
148+
.then(() => {
149+
this.dispatchEvent(
150+
new ShowToastEvent({
151+
title: 'Success',
152+
message: 'File attached',
153+
variant: 'success'
154+
})
155+
);
156+
})
157+
.catch((e) => {
158+
this.dispatchEvent(
159+
new ShowToastEvent({
160+
title: 'Error uploading file',
161+
message: e.body.message,
162+
variant: 'error'
163+
})
164+
);
165+
});
166+
}
167+
}

0 commit comments

Comments
 (0)