Monday, 29 July 2019

Why eslint plugins are not applied when I am trying to use eslint nodejs api?

I want to use eslint api in my node js script. I found this: https://eslint.org/docs/developer-guide/nodejs-api. So I am trying to create CLIEngine, load config and lint something using API.

When I am trying to lint some code using API I am getting error: Definition for rule <ruleName> was not found..

You can watch code in this repo: https://github.com/sharikovvladislav/eslint-try-api-with-plugins

Here is whole my code:

const CLIEngine = require('eslint').CLIEngine;
const Linter = require('eslint').Linter;
const path = require('path');

const cli = new CLIEngine({
    configPath: path.resolve(process.cwd(), '.eslintrc.json')
});

const linter = new Linter();

const result = linter.verifyAndFix('var foo', cli.getConfigForFile("script.js"));

console.log(result);

In result I get something like this:

 ~/tmp/test-eslint-with-plugins  node script.js
{ fixed: false,
  messages:
   [ { ruleId: 'node/no-extraneous-require',
       message:
        'Definition for rule \'node/no-extraneous-require\' was not found.',
       line: 1,
       column: 1,
       endLine: 1,
       endColumn: 2,
       severity: 2,
       nodeType: null }
  // ....
]
}

I have this in my package dependency:

    "eslint": "^6.1.0",
    "eslint-plugin-node": "^9.1.0"

This is my eslintrc:

{
    "extends": [
        "eslint:recommended",
        "plugin:node/recommended"
    ],
    "rules": {
        "node/exports-style": ["error", "module.exports"],
        "node/file-extension-in-import": ["error", "always"],
        "node/prefer-global/buffer": ["error", "always"],
        "node/prefer-global/console": ["error", "always"],
        "node/prefer-global/process": ["error", "always"],
        "node/prefer-global/url-search-params": ["error", "always"],
        "node/prefer-global/url": ["error", "always"],
        "node/prefer-promises/dns": "error",
        "node/prefer-promises/fs": "error"
    }
}

So I specified some plugins and rules. Looks like everything is correct.

I tried to debug a bit and I realised that CLI is created (looks like) normally. Also, config file parsed correctly. I can see this in config properties:

cli.getConfigForFile("script.js").plugins
>> ["node"]
Object.keys(cli.getConfigForFile("script.js").rules).filter(key => key.startsWith('node'))
>> ["node/exports-style", "node/file-extension-in-import", "node/prefer-global/buffer", "node/prefer-global/console", "node/prefer-global/process", "node/prefer-global/url-search-params", "node/prefer-global/url", "node/prefer-promises/dns", "node/prefer-promises/fs", "node/no-deprecated-api", "node/no-extraneous-require", "node/no-missing-require", "node/no-unpublished-bin", "node/no-unpublished-require", "node/no-unsupported-features/es-builtins", "node/no-unsupported-features/es-syntax", "node/no-unsupported-features/node-builtins", "node/process-exit-as-throw", "node/shebang", "node/no-extraneous-import", "node/no-missing-import", "node/no-unpublished-import"]

Why do I get Definition for rule \'node/no-extraneous-require\' was not found. error (and other errors like this)? What I am missing?



from Why eslint plugins are not applied when I am trying to use eslint nodejs api?

Alamofire in iOS is Receiving Dictionary Instead of Array

I am working on creating tables in iOS and am supposed to be receiving the required data in the form of JSON arrays. However, when I get the data in my iOS app it is presented as an unsorted dictionary instead. I was able to run the GET request in Postman and receive the data correctly, but when I receive it through Alamofire in my iOS app it is not formatted correctly. Is it possible that Alamofire would reformat the JSON somehow and convert all arrays to dictionaries, and can I override that setting somehow?

Here is an example of the column section of the JSON in Postman:

enter image description here

And here is what I am receiving through Alamofire:

enter image description here

This is how I am attempting to access the JSON

if let jsonColumns = json["columns"] as? [[String:Any]] {
        for columns in jsonColumns {
            for column in columns.values {
                if let c = column as? [String:Any] {
                    if c["isVisible"] as? Bool == false {
                        continue
                    }
                    if let columnName = c["name"] as? String {
                        dataSet.columns.append(columnName)
                    }
                }
            }
        }
    }



from Alamofire in iOS is Receiving Dictionary Instead of Array

Singletons in Swift 5

Here's precisely how I make a singleton,

public class Model
    {
    static let shared = Model()
    // For ocd friends. Add this line: private init() {}

    func test()->Double
        {
        return 3.33
        }
    }

then elsewhere...

class ViewController:UIViewController
    {
    override func viewDidLoad()
        {
        super.viewDidLoad()
        print("Holy singleton test, Batman! \( Model.shared.test() )")
        }
    }

What about in Swift 5?

Any new dramas or insights? Have they perhaps added "actual" singletons, or?



from Singletons in Swift 5