Skip to content

Commit

Permalink
Update eslint configuration and adding comment to all functions which…
Browse files Browse the repository at this point in the history
… do not have them.

- Update eslint to throw errors when functions don't have documentation.
- Ignoring eslint missing comments for spa, generated-html and src-electron/generator/matter
- Update comments on all the js functions
- Add eslint to pre-commit hook
- JIRA: ZAPP-1143
  • Loading branch information
brdandu committed Aug 30, 2024
1 parent 5d67834 commit 28a6e91
Show file tree
Hide file tree
Showing 85 changed files with 3,029 additions and 103 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/dist
src-script/download-artifact.js
/spa
/generated-html
/src-electron/generator/matter
24 changes: 22 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ module.exports = {

// random rules added
'no-undef': 'off',
'no-unused-vars': 'off'
}
'no-unused-vars': 'off',
'require-jsdoc': [
'error',
{
require: {
FunctionDeclaration: true,
MethodDefinition: true,
ClassDeclaration: false,
ArrowFunctionExpression: false,
FunctionExpression: false
}
}
]
},
overrides: [
{
files: ['test/**/*.js'], // Path to the directory you want to ignore
rules: {
'require-jsdoc': 'off' // Disable the require-jsdoc rule for this directory
}
}
]
}
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ echo "🚀 > JSdoc regen..."
npx jsdoc src-electron src-shared -r -d ./generated-html/

echo "🚀 > Eslint..."
npx eslint --ext .js,.vue src src-electron src-shared src-script test
npx eslint .

echo "🚀 > Reset version in package.json to 0.0.0..."
src-script/zap-update-package-version.js -fake
Expand Down
4 changes: 4 additions & 0 deletions src-electron/client/ipc-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const client = {

let lastPong = ''

/**
* Log ipc client message
* @param {*} msg
*/
function log(msg) {
env.logIpc(`Ipc client: ${msg}`)
}
Expand Down
25 changes: 25 additions & 0 deletions src-electron/db/db-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ const dbMapping = require('./db-mapping.js')
//
let inTransaction = false

/**
* Begin Database transaction.
* @param {*} db
* @param {*} resolve
* @param {*} reject
*/
function executeBeginTransaction(db, resolve, reject) {
db.run('BEGIN TRANSACTION', [], function (err) {
if (err) {
Expand All @@ -50,6 +56,12 @@ function executeBeginTransaction(db, resolve, reject) {
})
}

/**
* Delay database transaction.
* @param {*} db
* @param {*} resolve
* @param {*} reject
*/
function delayBeginTransaction(db, resolve, reject) {
let cnt = 0
let interval = setInterval(() => {
Expand Down Expand Up @@ -485,6 +497,13 @@ async function determineIfSchemaShouldLoad(db, filePath, crc) {
return result
}

/**
* Update the CRC of the sql schema file.
* @param {*} db
* @param {*} filePath
* @param {*} crc
* @returns promise of insert transaction.
*/
async function updateCurrentSchemaCrc(db, filePath, crc) {
return dbInsert(
db,
Expand All @@ -493,6 +512,12 @@ async function updateCurrentSchemaCrc(db, filePath, crc) {
)
}

/**
* Load SQL Schema
* @param {*} db
* @param {*} schemaContent
* @returns Promise of loaded schema
*/
async function performSchemaLoad(db, schemaContent) {
return new Promise((resolve, reject) => {
env.logSql('Loading schema.')
Expand Down
36 changes: 36 additions & 0 deletions src-electron/db/query-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
const dbApi = require('./db-api.js')
const dbMapping = require('./db-mapping.js')

/**
* Get access operations for package IDs given.
* @param {*} db
* @param {*} packageIds
* @returns promise of access operation.
*/
async function selectAccessOperations(db, packageIds) {
return dbApi
.dbAll(
Expand All @@ -36,6 +42,12 @@ SELECT NAME, DESCRIPTION FROM OPERATION WHERE PACKAGE_REF IN (${dbApi.toInClause
.then((rows) => rows.map(dbMapping.map.accessOperation))
}

/**
* Get access roles for package IDs given.
* @param {*} db
* @param {*} packageIds
* @returns promise of access roles.
*/
async function selectAccessRoles(db, packageIds) {
return dbApi
.dbAll(
Expand All @@ -49,6 +61,12 @@ SELECT NAME, DESCRIPTION, LEVEL FROM ROLE WHERE PACKAGE_REF IN (${dbApi.toInClau
.then((rows) => rows.map(dbMapping.map.accessRole))
}

/**
* Get access modifiers for package IDs given.
* @param {*} db
* @param {*} packageIds
* @returns promise of access modifiers.
*/
async function selectAccessModifiers(db, packageIds) {
return dbApi
.dbAll(
Expand Down Expand Up @@ -99,6 +117,12 @@ ORDER BY OPERATION.NAME, ROLE.NAME, ACCESS_MODIFIER.NAME
.then((rows) => rows.map(dbMapping.map.access))
}

/**
* Get attribute access information for the attribute id given.
* @param {*} db
* @param {*} attributeId
* @returns Promise of attribute access information
*/
async function selectAttributeAccess(db, attributeId) {
return dbApi
.dbAll(
Expand Down Expand Up @@ -128,6 +152,12 @@ ORDER BY OPERATION.NAME, ROLE.NAME, ACCESS_MODIFIER.NAME
.then((rows) => rows.map(dbMapping.map.access))
}

/**
* Get command access information for the attribute id given.
* @param {*} db
* @param {*} commandId
* @returns Promise of command access information
*/
async function selectCommandAccess(db, commandId) {
return dbApi
.dbAll(
Expand Down Expand Up @@ -157,6 +187,12 @@ ORDER BY OPERATION.NAME, ROLE.NAME, ACCESS_MODIFIER.NAME
.then((rows) => rows.map(dbMapping.map.access))
}

/**
* Get event access information for the attribute id given.
* @param {*} db
* @param {*} eventId
* @returns Promise of event access information
*/
async function selectEventAccess(db, eventId) {
return dbApi
.dbAll(
Expand Down
7 changes: 6 additions & 1 deletion src-electron/db/query-atomic.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ FROM ATOMIC
const cacheKey = 'atomic'

// Raw query versions without caching.

/**
* Get all atomic data type information
* @param {*} db
* @param {*} packageId
* @returns atomic data types
*/
async function selectAllAtomics(db, packageId) {
let rows = await dbApi.dbAll(
db,
Expand Down
27 changes: 26 additions & 1 deletion src-electron/db/query-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,6 @@ async function selectAttributeDetailsFromEnabledClusters(
* Union is used to get separate entries of attributes w.r.t to default, minimum
* and maximum values
*/

async function selectAttributeBoundDetails(
db,
endpointsAndClusters,
Expand Down Expand Up @@ -793,6 +792,15 @@ async function selectReportableAttributeDetailsFromEnabledClustersAndEndpoints(
.then((rows) => rows.map(mapFunction))
}

/**
* Get attribute data by attribute code.
* @param {*} db
* @param {*} packageIds
* @param {*} clusterCode
* @param {*} attributeCode
* @param {*} manufacturerCode
* @returns promise of attribute data
*/
async function selectAttributeByCode(
db,
packageIds,
Expand All @@ -818,6 +826,15 @@ async function selectAttributeByCode(
}
}

/**
* Get attribute information by code for attributes which are not global.
* @param {*} db
* @param {*} packageIds
* @param {*} clusterCode
* @param {*} attributeCode
* @param {*} manufacturerCode
* @returns promise of attribute data
*/
async function selectNonGlobalAttributeByCode(
db,
packageIds,
Expand Down Expand Up @@ -878,6 +895,14 @@ WHERE A.PACKAGE_REF IN (${dbApi.toInClause(packageIds)})
.then(dbMapping.map.attribute)
}

/**
* Get global attributes by their attribute code.
* @param {*} db
* @param {*} packageIds
* @param {*} attributeCode
* @param {*} manufacturerCode
* @returns promise of global attribute data
*/
async function selectGlobalAttributeByCode(
db,
packageIds,
Expand Down
13 changes: 13 additions & 0 deletions src-electron/db/query-bitmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ WHERE PACKAGE_REF = ? ORDER BY NAME`,
return rows.map(dbMapping.map.bitmap)
}

/**
* Get bitmap by name from the given package IDs.
* @param {*} db
* @param {*} packageIds
* @param {*} name
* @returns promise of bitmap
*/
async function selectBitmapByName(db, packageIds, name) {
return dbApi
.dbGet(
Expand Down Expand Up @@ -104,6 +111,12 @@ async function selectBitmapByNameAndClusterId(db, name, clusterId, packageIds) {
}
}

/**
* Get Bitmap information by Bitmap ID.
* @param {*} db
* @param {*} id
* @returns Promise of bitmap
*/
async function selectBitmapById(db, id) {
return dbApi
.dbGet(
Expand Down
Loading

0 comments on commit 28a6e91

Please sign in to comment.