Home  >  Article  >  CMS Tutorial  >  Detailed explanation of how to set up an atom environment for WordPress development

Detailed explanation of how to set up an atom environment for WordPress development

藏色散人
藏色散人forward
2020-01-26 16:42:592532browse

The following column WordPress Tutorial will introduce to you how to set up an atom environment for WordPress development. I hope it will be helpful to friends in need!

Detailed explanation of how to set up an atom environment for WordPress development

WordPress is really a very strange project. Many of its coding standards are so different from PSR2, such as general PHP projects all require spaces to replace the TAB key, but only WordPress requires that the TAB key itself be used for indentation, and so on. So much so that an atom environment must be set up specifically for its development.

1. Find and install the project-manager plug-in in atom. With it, we can create our own special environment for the WordPress project.

2. According to the documentation, after selecting Save Project in the menu, it will create a ~/.atom/projects.cson file, which contains the path of your project and other basic information. .

3. In the root directory of your project, create a file named project.cson with the following content:

settings:
  "*":
    "linter-phpcs.codeStandardOrConfigFile": "WordPress"
  ".html.php.text":
    "editor.tabType": "hard"

The third line means: only for this project WordPress validation.

Lines 4 and 5 mean: Only perform hard TAB on php files.

In this way, all your other PHP projects are still verified using the PSR2 standard and are soft TABs, that is, TABs will be converted to spaces, but only the PHP projects in this project are hard TABs, and other files For example, JS, etc. are still soft TAB.

New method

Project Management in Atom is not easy to use. In the end, I used the editorconfig plus phpcs method to set it up:

editorconfig

First, create an .editorconfig file in the root directory of the project:

root = true
[*.php]
indent_style = tab
[*.scss]
indent_style = space
indent_size = 2

This stipulates that the indentation method of the php file must be Use the TAB key.

Note: Atom must change the indentation mode to Auto, otherwise the settings in editorconfig will not work.

phpcs.xml

Then, create a phpcs.xml file in the project root directory:

<?xml version="1.0"?>
<ruleset name="Custom Standard">
 <rule ref="WordPress"/>
</ruleset>

Here, we tell phpcs, this Project will use WordPress verification.

Related recommendations: "atom usage tutorial"

The above is the detailed content of Detailed explanation of how to set up an atom environment for WordPress development. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete