Skip to content

Commit 340d76a

Browse files
Enable eslint no-console
1 parent c08aa27 commit 340d76a

31 files changed

Lines changed: 228 additions & 175 deletions

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@typescript-eslint"
1515
],
1616
"rules": {
17+
"no-console": "error",
1718
"complexity": ["warn", 15],
1819
"no-unused-vars": ["warn", {
1920
"argsIgnorePattern": "^_",

src/acl/access-controller.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { AccessGroups } from './access-groups'
99
import { DataBrowserContext } from 'pane-registry'
1010
import { shortNameForFolder } from './acl-control'
1111
import utils from '../utils.js'
12+
import { debug } from '../debug'
1213

1314
/**
1415
* Rendered HTML component used in the databrowser's Sharing pane.
@@ -161,7 +162,7 @@ export class AccessController {
161162
private async addAcls (): Promise<void> {
162163
if (!this.defaultHolder || !this.defaultACLDoc) {
163164
const message = 'Unable to find defaults to copy'
164-
console.error(message)
165+
debug.error(message)
165166
return Promise.reject(message)
166167
}
167168
const aclGraph = adoptACLDefault(this.targetDoc, this.targetACLDoc, this.defaultHolder, this.defaultACLDoc)
@@ -172,7 +173,7 @@ export class AccessController {
172173
return Promise.resolve()
173174
} catch (error) {
174175
const message = ` Error writing back access control file! ${error}`
175-
console.error(message)
176+
debug.error(message)
176177
return Promise.reject(message)
177178
}
178179
}
@@ -190,11 +191,11 @@ export class AccessController {
190191
this.prospectiveDefaultHolder = await getProspectiveHolder(this.targetDoc.uri)
191192
} catch (error) {
192193
// No need to show this error in status, but good to warn about it in console
193-
console.warn(error)
194+
debug.warn(error)
194195
}
195196
} catch (error) {
196197
const message = `Error deleting access control file: ${this.targetACLDoc}: ${error}`
197-
console.error(message)
198+
debug.error(message)
198199
return Promise.reject(message)
199200
}
200201
}
@@ -208,7 +209,7 @@ export class AccessController {
208209
} catch (error) {
209210
this.defaultsCombo = fallbackCombo
210211
this.defaultsDiffer = true
211-
console.error(error)
212+
debug.error(error)
212213
return Promise.reject(error)
213214
}
214215
}
@@ -242,7 +243,7 @@ export class AccessController {
242243
this.defaultsCombo.store = this.store
243244
}
244245
this.defaultsDiffer = !!this.defaultsCombo && !sameACL(this.mainCombo.aclMap, this.defaultsCombo.aclMap)
245-
console.log('ACL modification: success!')
246+
debug.log('ACL modification: success!')
246247
resolve()
247248
}
248249
))

src/acl/access-groups.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import ns from '../ns'
1111
import { AccessController } from './access-controller'
1212
import { AgentMapMap, ComboList, PartialAgentTriple } from './types'
1313
import { AddAgentButtons } from './add-agent-buttons'
14+
import { debug } from '../debug'
1415

1516
const ACL = ns.acl
1617

@@ -175,18 +176,18 @@ export class AccessGroups {
175176
const agent = findAgent(uri, this.store) // eg 'agent', 'origin', agentClass'
176177
const thing = sym(uri)
177178
if (!agent && !secondAttempt) {
178-
console.log(` Not obvious: looking up dropped thing ${thing}`)
179+
debug.log(` Not obvious: looking up dropped thing ${thing}`)
179180
try {
180181
await (this.store as any).fetcher.load(thing.doc())
181182
} catch (error) {
182183
const message = `Ignore error looking up dropped thing: ${error}`
183-
console.error(message)
184+
debug.error(message)
184185
return Promise.reject(new Error(message))
185186
}
186187
return this.handleDroppedUri(uri, combo, true)
187188
} else if (!agent) {
188189
const error = ` Error: Drop fails to drop appropriate thing! ${uri}`
189-
console.error(error)
190+
debug.error(error)
190191
return Promise.reject(new Error(error))
191192
}
192193
this.setACLCombo(combo, uri, agent, this.controller.subject)
@@ -198,7 +199,7 @@ export class AccessGroups {
198199
}
199200
this.removeAgentFromCombos(uri) // Combos are mutually distinct
200201
this.byCombo[combo].push([res.pred, res.obj.uri])
201-
console.log(`ACL: setting access to ${subject} by ${res.pred}: ${res.obj}`)
202+
debug.log(`ACL: setting access to ${subject} by ${res.pred}: ${res.obj}`)
202203
}
203204

204205
private removeAgentFromCombos (uri: string): void {
@@ -242,7 +243,7 @@ function findAgent (uri, kb): PartialAgentTriple | null {
242243
const obj = sym(uri)
243244
const types = kb.findTypeURIs(obj)
244245
for (const ty in types) {
245-
console.log(' drop object type includes: ' + ty)
246+
debug.log(' drop object type includes: ' + ty)
246247
}
247248
// An Origin URI is one like https://fred.github.io eith no trailing slash
248249
if (uri.startsWith('http') && uri.split('/').length === 3) {
@@ -256,7 +257,7 @@ function findAgent (uri, kb): PartialAgentTriple | null {
256257
uri.endsWith('/')
257258
) {
258259
// there IS third slash
259-
console.log('Assuming final slash on dragged origin URI was unintended!')
260+
debug.log('Assuming final slash on dragged origin URI was unintended!')
260261
return { pred: 'origin', obj: sym(uri.slice(0, -1)) } // Fix a URI where the drag and drop system has added a spurious slash
261262
}
262263

@@ -288,6 +289,6 @@ function findAgent (uri, kb): PartialAgentTriple | null {
288289
if (ns.solid('AppProviderClass').uri in types) {
289290
return { pred: 'originClass', obj: obj }
290291
}
291-
console.log(' Triage fails for ' + uri)
292+
debug.log(' Triage fails for ' + uri)
292293
return null
293294
}

src/acl/acl-control.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { DataBrowserContext } from 'pane-registry'
1313
import { AccessController } from './access-controller'
1414
import { getClasses } from '../jss'
1515
import { styles } from './styles'
16+
import { debug } from '../debug'
1617

1718
/**
1819
* See https://coshx.com/preventing-drag-and-drop-disasters-with-a-chrome-userscript
@@ -27,7 +28,7 @@ import { styles } from './styles'
2728
* @returns void
2829
*/
2930
export function preventBrowserDropEvents (document: HTMLDocument): void {
30-
console.log('preventBrowserDropEvents called.')
31+
debug.log('preventBrowserDropEvents called.')
3132
const global: any = window
3233
if (typeof global !== 'undefined') {
3334
if (global.preventBrowserDropEventsDone) return
@@ -49,7 +50,7 @@ export function preventBrowserDropEvents (document: HTMLDocument): void {
4950
) {
5051
e.stopPropagation()
5152
e.preventDefault()
52-
console.log(
53+
debug.log(
5354
'@@@@ document-level DROP suppressed: ' + e.dataTransfer.dropEffect
5455
)
5556
}
@@ -180,7 +181,7 @@ async function loadController (
180181
return resolve(getController(prospectiveDefaultHolder))
181182
} catch (error) {
182183
// No need to show this error in status, but good to warn about it in console
183-
console.warn(error)
184+
debug.warn(error)
184185
}
185186
}
186187
return resolve(getController())

src/acl/acl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import ns from '../ns'
1010
import kb from '../store.js'
1111
import utils from '../utils'
1212
import { AgentMapMap, ComboList } from './types'
13+
import { debug } from '../debug'
1314

1415
/**
1516
* Take the "default" ACL and convert it into the equivlent ACL
@@ -373,7 +374,7 @@ export function fixIndividualCardACL (person: $rdf.NamedNode, log: Function, cal
373374
* This function is used by [[fixIndividualCardACL]]
374375
*/
375376
export function fixIndividualACL (item: $rdf.NamedNode, subjects: Array<$rdf.NamedNode>, log: Function, callbackFunction: Function): void {
376-
log = log || console.log
377+
log = log || debug.log
377378
const doc = item.doc()
378379
getACLorDefault(doc, function (
379380
ok,

src/acl/add-agent-buttons.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { logInLoadProfile } from '../authn/authn'
1111
import utils from '../utils'
1212
import { NamedNode } from 'rdflib'
1313
import { AuthenticationContext } from '../authn/types'
14+
import { debug } from '../debug'
1415

1516
/**
1617
* Renders the Sharing pane's "+" button and the menus behind it,
@@ -227,7 +228,7 @@ export class AddAgentButtons {
227228
return Promise.reject(new Error('Not a http URI'))
228229
}
229230
// @@ check it actually is a person and has an owner who agrees they own it
230-
console.log(`Adding to ACL person: ${name}`)
231+
debug.log(`Adding to ACL person: ${name}`)
231232
await this.groupList.addNewURI(name)
232233
this.toggleBar()
233234
}
@@ -241,7 +242,7 @@ export class AddAgentButtons {
241242
return Promise.reject(new Error('Not a http URI'))
242243
}
243244
// @@ check it actually is a group and has an owner who agrees they own it
244-
console.log('Adding to ACL group: ' + name)
245+
debug.log('Adding to ACL group: ' + name)
245246
await this.groupList.addNewURI(name)
246247
this.toggleBar()
247248
}
@@ -259,7 +260,7 @@ export class AddAgentButtons {
259260
return Promise.reject(new Error('Not a http URI'))
260261
}
261262
// @@ check it actually is a bot and has an owner who agrees they own it
262-
console.log('Adding to ACL bot: ' + name)
263+
debug.log('Adding to ACL bot: ' + name)
263264
await this.groupList.addNewURI(name)
264265
this.toggleBar()
265266
}
@@ -273,7 +274,7 @@ export class AddAgentButtons {
273274
return Promise.reject(new Error('Not a domain name'))
274275
}
275276
const origin = 'https://' + name
276-
console.log('Adding to ACL origin: ' + origin)
277+
debug.log('Adding to ACL origin: ' + origin)
277278
this.toggleBar()
278279
return origin
279280
}

0 commit comments

Comments
 (0)