Skip to content

Commit

Permalink
fix: Adds noconsole rule to guard against casual console.log msgs #625
Browse files Browse the repository at this point in the history
* Uses eslint-disable-next-line to keep those instances where it makes
  sense to use console.[log|error]

issue #625
  • Loading branch information
phantomjinx committed Oct 19, 2023
1 parent fd12d90 commit 921e9d2
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
},
},
],
'no-console': 'error',
},
root: true,
}
2 changes: 2 additions & 0 deletions packages/hawtio/scripts/generate-camel-svg-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ async function writeToIndex(svgpath, idx) {
}

if (!fs.existsSync(svgdir)) {
// eslint-disable-next-line no-console
console.error(`${svgdir} does not exist. Exiting`)
process.exit(1)
}
Expand All @@ -109,4 +110,5 @@ if (fs.existsSync(index)) {
fs.unlinkSync(index)
}

// eslint-disable-next-line no-console
writeToIndex(svgdir, index).catch(console.error)
4 changes: 4 additions & 0 deletions packages/hawtio/src/core/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ class LocalStorageHawtioLogger implements HawtioLogger {
const logLevel = this.loadLogLevel()
jsLogger.setLevel(logLevel)
} catch (e) {
// eslint-disable-next-line no-console
console.error('Failed to load log level from local storage:', e)
}

try {
const childLoggers = this.loadChildLoggers()
childLoggers.forEach(logger => this.get(logger.name).setLevel(logger.filterLevel))
} catch (e) {
// eslint-disable-next-line no-console
console.error('Failed to load child loggers from local storage:', e)
}

Expand All @@ -99,6 +101,7 @@ class LocalStorageHawtioLogger implements HawtioLogger {

const logLevel = this.LOG_LEVEL_MAP[level]
if (!logLevel) {
// eslint-disable-next-line no-console
console.error('Unknown log level:', level)
return this.INFO
}
Expand Down Expand Up @@ -136,6 +139,7 @@ class LocalStorageHawtioLogger implements HawtioLogger {
if (is(logger, type({ context: object() }))) {
allLoggers.push(logger.context as unknown as ChildLogger)
} else {
// eslint-disable-next-line no-console
console.error('Logger does not have context:', logger)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ export function createEndpointFromData(
endPointPath: string,
parameters: Record<string, string>,
) {
if (!componentName) console.error('createEndpointFromData: component name must be defined')
if (!componentName) log.error('createEndpointFromData: component name must be defined')

if (!endPointPath) console.error('createEndpointFromData: endpoint path must be defined')
if (!endPointPath) log.error('createEndpointFromData: endpoint path must be defined')

log.debug('Have endpoint data ' + JSON.stringify(parameters))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ let canDisplayInflightExchanges = false
jest.mock('./exchanges-service', () => {
return {
getInflightExchanges: jest.fn(async () => {
console.log('using mocked getInflightExchanges()')
return Promise.resolve(xchgs)
}),
canBrowseInflightExchanges: jest.fn(async (node: MBeanNode): Promise<boolean> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Connection, ConnectionTestResult, Connections, IConnectService } from '

class MockConnectService implements IConnectService {
constructor() {
// eslint-disable-next-line no-console
console.log('Using mock connect service')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import jmxCamelResponse from './jmx-camel-tree.json'

class MockJolokiaService implements IJolokiaService {
constructor() {
// eslint-disable-next-line no-console
console.log('Using mock jolokia service')
}

Expand Down
1 change: 1 addition & 0 deletions packages/hawtio/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fetchMock.enableMocks()

// Default mock response for every usage of fetch
fetchMock.mockResponse(req => {
// eslint-disable-next-line no-console
console.log('Mock fetch:', req.url)
let res = '{}'
switch (req.url) {
Expand Down

0 comments on commit 921e9d2

Please sign in to comment.