4

I've noticed Magento2 has Javascript Coding Standards, in which they reference an eslint config file.

Suppose I have an M2 project I'm developing with a large group of folks and I'd like the team to adhere to these standards. How can I leverage this? For example, do I need to make a custom grunt task, or is there one already present somewhere?

Ideally I'd like something like grunt eslint that would look over all the javascript files in the custom theme and extensions.

1 Answer 1

1

🔧 Setup:

  • make sure you have the official magento standard composer package installed as a dev dependency:
    composer require --dev magento/magento-coding-standard:^35
    
  • install its npm dependencies:
    cd vendor/magento/magento-coding-standard && npm install && cd -
    

▶️ Usage:

npm --prefix vendor/magento/magento-coding-standard/ run eslint -- "$(pwd)"/app/{code,design}/

Ideally you should put this into a pipeline in your source control platform to get new PRs/MRs analyzed automatically, replacing the "$(pwd)"/app/{code,design}/ at the end with the list of files changed (just ensure the list contain absolute paths)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.