Browse Source

storage-node: Fix linter errors.

Shamil Gadelshin 4 years ago
parent
commit
9ef0c8511f

+ 5 - 7
storage-node/packages/cli/bin/cli.js

@@ -63,7 +63,7 @@ function assertFile(name, filename) {
   assert(fs.statSync(filename).isFile(), `Path "${filename}" is not a file, aborting!`)
 }
 
-function load_identity(api, filename, passphrase) {
+function loadIdentity(api, filename, passphrase) {
   if (filename) {
     assertFile('keyfile', filename)
     api.identities.loadUnlock(filename, passphrase)
@@ -76,15 +76,13 @@ function load_identity(api, filename, passphrase) {
 const commands = {
   // add Alice well known account as storage provider
   'dev-init': async api => {
-    // dev accounts are automatically loaded, no need to add explicitly to keyring
-    // load_identity(api)
+    // dev accounts are automatically loaded, no need to add explicitly to keyring using loadIdentity(api)
     const dev = require('./dev')
     return dev.init(api)
   },
   // Checks that the setup done by dev-init command was successful.
   'dev-check': async api => {
-    // dev accounts are automatically loaded, no need to add explicitly to keyring
-    // load_identity(api)
+    // dev accounts are automatically loaded, no need to add explicitly to keyring using loadIdentity(api)
     const dev = require('./dev')
     return dev.check(api)
   },
@@ -93,7 +91,7 @@ const commands = {
   // resolve the ipns id to the asset put api url of the storage-node
   // before uploading..
   upload: async (api, url, filename, doTypeId, keyfile, passphrase) => {
-    load_identity(keyfile, passphrase)
+    loadIdentity(keyfile, passphrase)
     // Check parameters
     assertFile('file', filename)
 
@@ -234,7 +232,7 @@ async function main() {
     throw new Error('Need a command to run!')
   }
 
-  if (commands.hasOwnProperty(command)) {
+  if (Object.prototype.hasOwnProperty.call(commands, command)) {
     // Command recognized
     const args = _.clone(cli.input).slice(1)
     await commands[command](api, ...args)

+ 18 - 18
storage-node/packages/colossus/bin/cli.js

@@ -104,19 +104,19 @@ function startExpressApp(app, port) {
 }
 
 // Start app
-function start_all_services({ store, api, port }) {
+function startAllServices({ store, api, port }) {
   const app = require('../lib/app')(PROJECT_ROOT, store, api) // reduce falgs to only needed values
   return startExpressApp(app, port)
 }
 
 // Start discovery service app only
-function start_discovery_service({ api, port }) {
+function startDiscoveryService({ api, port }) {
   const app = require('../lib/discovery')(PROJECT_ROOT, api) // reduce flags to only needed values
   return startExpressApp(app, port)
 }
 
 // Get an initialized storage instance
-function get_storage(runtimeApi) {
+function getStorage(runtimeApi) {
   // TODO at some point, we can figure out what backend-specific connection
   // options make sense. For now, just don't use any configuration.
   const { Storage } = require('@joystream/storage-node-backend')
@@ -136,7 +136,7 @@ function get_storage(runtimeApi) {
   return Storage.create(options)
 }
 
-async function init_api_production({ wsProvider, providerId, keyFile, passphrase }) {
+async function initApiProduction({ wsProvider, providerId, keyFile, passphrase }) {
   // Load key information
   const { RuntimeApi } = require('@joystream/storage-runtime-api')
 
@@ -166,7 +166,7 @@ async function init_api_production({ wsProvider, providerId, keyFile, passphrase
   return api
 }
 
-async function init_api_development() {
+async function initApiDevelopment() {
   // Load key information
   const { RuntimeApi } = require('@joystream/storage-runtime-api')
 
@@ -185,7 +185,7 @@ async function init_api_development() {
   return api
 }
 
-function get_service_information(publicUrl) {
+function getServiceInformation(publicUrl) {
   // For now assume we run all services on the same endpoint
   return {
     asset: {
@@ -199,17 +199,17 @@ function get_service_information(publicUrl) {
   }
 }
 
-async function announce_public_url(api, publicUrl) {
+async function announcePublicUrl(api, publicUrl) {
   // re-announce in future
   const reannounce = function (timeoutMs) {
-    setTimeout(announce_public_url, timeoutMs, api, publicUrl)
+    setTimeout(announcePublicUrl, timeoutMs, api, publicUrl)
   }
 
   debug('announcing public url')
   const { publish } = require('@joystream/service-discovery')
 
   try {
-    const serviceInformation = get_service_information(publicUrl)
+    const serviceInformation = getServiceInformation(publicUrl)
 
     const keyId = await publish.publish(serviceInformation)
 
@@ -238,14 +238,14 @@ if (!command) {
   command = 'server'
 }
 
-async function start_colossus({ api, publicUrl, port, flags }) {
+async function startColossus({ api, publicUrl, port, flags }) {
   // TODO: check valid url, and valid port number
-  const store = get_storage(api)
+  const store = getStorage(api)
   banner()
   const { startSyncing } = require('../lib/sync')
   startSyncing(api, { syncPeriod: SYNC_PERIOD_MS }, store)
-  announce_public_url(api, publicUrl)
-  return start_all_services({ store, api, port, flags }) // dont pass all flags only required values
+  announcePublicUrl(api, publicUrl)
+  return startAllServices({ store, api, port, flags }) // dont pass all flags only required values
 }
 
 const commands = {
@@ -254,16 +254,16 @@ const commands = {
 
     if (cli.flags.dev) {
       const dev = require('../../cli/bin/dev')
-      api = await init_api_development()
+      api = await initApiDevelopment()
       port = dev.developmentPort()
       publicUrl = `http://localhost:${port}/`
     } else {
-      api = await init_api_production(cli.flags)
+      api = await initApiProduction(cli.flags)
       publicUrl = cli.flags.publicUrl
       port = cli.flags.port
     }
 
-    return start_colossus({ api, publicUrl, port })
+    return startColossus({ api, publicUrl, port })
   },
   discovery: async () => {
     debug('Starting Joystream Discovery Service')
@@ -271,7 +271,7 @@ const commands = {
     const wsProvider = cli.flags.wsProvider
     const api = await RuntimeApi.create({ provider_url: wsProvider })
     const port = cli.flags.port
-    await start_discovery_service({ api, port })
+    await startDiscoveryService({ api, port })
   },
 }
 
@@ -282,7 +282,7 @@ async function main() {
     command = 'server'
   }
 
-  if (commands.hasOwnProperty(command)) {
+  if (Object.prototype.hasOwnProperty.call(commands, command)) {
     // Command recognized
     const args = _.clone(cli.input).slice(1)
     await commands[command](...args)

+ 2 - 2
storage-node/packages/colossus/lib/app.js

@@ -35,7 +35,7 @@ const fileUploads = require('./middleware/file_uploads')
 const pagination = require('@joystream/storage-utils/pagination')
 
 // Configure app
-function create_app(projectRoot, storage, runtime) {
+function createApp(projectRoot, storage, runtime) {
   const app = express()
   app.use(cors())
   app.use(bodyParser.json())
@@ -71,4 +71,4 @@ function create_app(projectRoot, storage, runtime) {
   return app
 }
 
-module.exports = create_app
+module.exports = createApp

+ 2 - 2
storage-node/packages/colossus/lib/discovery.js

@@ -33,7 +33,7 @@ const path = require('path')
 const validateResponses = require('./middleware/validate_responses')
 
 // Configure app
-function create_app(projectRoot, runtime) {
+function createApp(projectRoot, runtime) {
   const app = express()
   app.use(cors())
   app.use(bodyParser.json())
@@ -67,4 +67,4 @@ function create_app(projectRoot, runtime) {
   return app
 }
 
-module.exports = create_app
+module.exports = createApp

+ 1 - 1
storage-node/packages/colossus/lib/sync.js

@@ -31,7 +31,7 @@ async function syncCallback(api, storage) {
 
   // Iterate over all sync objects, and ensure they're synced.
   const allChecks = knownContentIds.map(async contentId => {
-    /* eslint-disable prefer-const */
+    // eslint-disable-next-line prefer-const
     let { relationship, relationshipId } = await api.assets.getStorageRelationshipAndId(providerId, contentId)
 
     // get the data object

+ 12 - 12
storage-node/packages/discovery/discover.js

@@ -61,7 +61,7 @@ async function getIpnsIdentity(storageProviderId, runtimeApi) {
  * @param {string} gateway - optional ipfs http gateway url to perform ipfs queries
  * @returns { Promise<object> } - the published service information
  */
-async function discover_over_ipfs_http_gateway(storageProviderId, runtimeApi, gateway = 'http://localhost:8080') {
+async function discoverOverIpfsHttpGateway(storageProviderId, runtimeApi, gateway = 'http://localhost:8080') {
   storageProviderId = new BN(storageProviderId)
   const isProvider = await runtimeApi.workers.isStorageProvider(storageProviderId)
 
@@ -95,7 +95,7 @@ async function discover_over_ipfs_http_gateway(storageProviderId, runtimeApi, ga
  * @param {string} discoverApiEndpoint - url for a colossus discovery api endpoint
  * @returns { Promise<object> } - the published service information
  */
-async function discover_over_joystream_discovery_service(storageProviderId, runtimeApi, discoverApiEndpoint) {
+async function discoverOverJoystreamDiscoveryService(storageProviderId, runtimeApi, discoverApiEndpoint) {
   storageProviderId = new BN(storageProviderId)
   const isProvider = await runtimeApi.workers.isStorageProvider(storageProviderId)
 
@@ -137,7 +137,7 @@ async function discover_over_joystream_discovery_service(storageProviderId, runt
  * @param {RuntimeApi} runtimeApi - api instance to query the chain
  * @returns { Promise<object> } - the published service information
  */
-async function discover_over_local_ipfs_node(storageProviderId, runtimeApi) {
+async function discoverOverLocalIpfsNode(storageProviderId, runtimeApi) {
   storageProviderId = new BN(storageProviderId)
   const isProvider = await runtimeApi.workers.isStorageProvider(storageProviderId)
 
@@ -152,18 +152,18 @@ async function discover_over_local_ipfs_node(storageProviderId, runtimeApi) {
     throw new Error('no identity to resolve')
   }
 
-  const ipns_address = `/ipns/${identity}/`
+  const ipnsAddress = `/ipns/${identity}/`
 
   debug('resolved ipns to ipfs object')
   // Can this call hang forever!? can/should we set a timeout?
-  const ipfs_name = await ipfs.name.resolve(ipns_address, {
+  const ipfsName = await ipfs.name.resolve(ipnsAddress, {
     // don't recurse, there should only be one indirection to the service info file
     recursive: false,
     nocache: false,
   })
 
-  debug('getting ipfs object', ipfs_name)
-  const data = await ipfs.get(ipfs_name) // this can sometimes hang forever!?! can we set a timeout?
+  debug('getting ipfs object', ipfsName)
+  const data = await ipfs.get(ipfsName) // this can sometimes hang forever!?! can we set a timeout?
 
   // there should only be one file published under the resolved path
   const content = data[0].content
@@ -232,9 +232,9 @@ async function _discover(storageProviderId, runtimeApi) {
   let result
   try {
     if (inBrowser()) {
-      result = await discover_over_joystream_discovery_service(storageProviderId, runtimeApi)
+      result = await discoverOverJoystreamDiscoveryService(storageProviderId, runtimeApi)
     } else {
-      result = await discover_over_local_ipfs_node(storageProviderId, runtimeApi)
+      result = await discoverOverLocalIpfsNode(storageProviderId, runtimeApi)
     }
 
     debug(result)
@@ -266,7 +266,7 @@ async function _discover(storageProviderId, runtimeApi) {
 
 module.exports = {
   discover,
-  discover_over_joystream_discovery_service,
-  discover_over_ipfs_http_gateway,
-  discover_over_local_ipfs_node,
+  discoverOverJoystreamDiscoveryService,
+  discoverOverIpfsHttpGateway,
+  discoverOverLocalIpfsNode,
 }

+ 1 - 1
storage-node/packages/helios/bin/cli.js

@@ -61,7 +61,7 @@ async function main() {
   const endpoints = await Promise.all(
     providersStatuses.map(async ({ providerId }) => {
       try {
-        const serviceInfo = await discover.discover_over_joystream_discovery_service(providerId, runtime)
+        const serviceInfo = await discover.discoverOverJoystreamDiscoveryService(providerId, runtime)
 
         if (serviceInfo === null) {
           console.log(`provider ${providerId} has not published service information`)

+ 2 - 0
storage-node/packages/runtime-api/assets.js

@@ -130,6 +130,8 @@ class AssetsApi {
    */
   async createAndReturnStorageRelationship(providerAccountId, storageProviderId, contentId) {
     contentId = parseContentId(contentId)
+    // TODO: rewrite this method to async-await style
+    // eslint-disable-next-line  no-async-promise-executor
     return new Promise(async (resolve, reject) => {
       try {
         await this.createStorageRelationship(providerAccountId, storageProviderId, contentId, events => {

+ 3 - 0
storage-node/packages/runtime-api/identities.js

@@ -110,6 +110,9 @@ class IdentitiesApi {
   /*
    * Ask for a passphrase
    */
+
+  /* eslint-disable class-methods-use-this */
+  // Disable lint because the method used by a mocking library.
   askForPassphrase(address) {
     // Query for passphrase
     const prompt = require('password-prompt')

+ 4 - 0
storage-node/packages/runtime-api/index.js

@@ -183,6 +183,8 @@ class RuntimeApi {
       // If the nonce isn't available, get it from chain.
       if (!nonce) {
         // current nonce
+        // TODO: possible race condition here found by the linter
+        // eslint-disable-next-line require-atomic-updates
         nonce = await this.api.query.system.accountNonce(accountId)
         debug(`Got nonce for ${accountId} from chain: ${nonce}`)
       }
@@ -284,6 +286,8 @@ class RuntimeApi {
   async signAndSendThenGetEventResult(senderAccountId, tx, { eventModule, eventName, eventProperty }) {
     // event from a module,
     const subscribed = [[eventModule, eventName]]
+    // TODO: rewrite this method to async-await style
+    // eslint-disable-next-line  no-async-promise-executor
     return new Promise(async (resolve, reject) => {
       try {
         await this.signAndSend(senderAccountId, tx, 1, subscribed, events => {

+ 2 - 0
storage-node/packages/storage/storage.js

@@ -234,6 +234,8 @@ class Storage {
    * that time.
    */
   async withSpecifiedTimeout(timeout, operation) {
+    // TODO: rewrite this method to async-await style
+    // eslint-disable-next-line  no-async-promise-executor
     return new Promise(async (resolve, reject) => {
       try {
         resolve(await new Promise(operation))