{"id":253,"date":"2023-04-12T20:23:07","date_gmt":"2023-04-12T20:23:07","guid":{"rendered":"https:\/\/www.w3computing.com\/articles\/?p=253"},"modified":"2023-08-23T16:22:00","modified_gmt":"2023-08-23T16:22:00","slug":"javascript-code-analysis-linting-eslint-prettier-jshint","status":"publish","type":"post","link":"https:\/\/www.w3computing.com\/articles\/javascript-code-analysis-linting-eslint-prettier-jshint\/","title":{"rendered":"JavaScript Code Analysis and Linting: ESLint, Prettier, and JSHint"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Code analysis and linting play a critical role in JavaScript development by helping developers identify and fix potential issues early in the development process. These tools enforce coding standards, improve code quality, and maintain a consistent code style across projects. With the growing complexity of JavaScript applications and the increasing number of developers collaborating on codebases, using linting tools has become a necessity for ensuring maintainability and reducing the likelihood of bugs and errors.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the JavaScript ecosystem, there are several popular linting tools that developers can choose from, each with its own strengths and weaknesses. ESLint is the most widely used tool, offering a highly customizable and extensible platform for detecting and fixing code issues. Prettier is an opinionated code formatter that focuses on maintaining a consistent code style across projects. JSHint, although not as feature-rich as ESLint, is a lightweight and fast tool that helps developers catch common errors and maintain code quality.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Code Analysis and Linting Concepts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To better understand the benefits of using tools like ESLint, Prettier, and JSHint, it&#8217;s essential to grasp the core concepts related to code analysis and linting. These concepts include static code analysis, code formatting, linting rules, syntax checking, and code style enforcement.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.1 Static code analysis<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Static code analysis is the process of examining source code without executing it, identifying potential issues such as programming errors, code smells, and security vulnerabilities. By catching these issues early in the development process, developers can reduce the number of bugs and improve overall code quality. Static code analysis can also help enforce coding standards, making it easier for teams to collaborate effectively.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.2 Code formatting<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Code formatting refers to the arrangement and appearance of code elements, such as indentation, line length, and whitespace. Properly formatted code is easier to read and understand, leading to fewer errors and improved maintainability. Automatic code formatting tools like Prettier can help ensure that code consistently follows a given style, reducing the need for manual adjustments and style-related discussions among team members.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.3 Linting rules<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Linting rules are a set of predefined guidelines that dictate how code should be written, helping to enforce best practices and maintain consistency across a project. These rules can cover various aspects of code, including syntax, performance, security, and style. Linting tools like ESLint and JSHint allow developers to configure and enforce custom rules tailored to their projects&#8217; needs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.4 Syntax checking<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Syntax checking is the process of examining code for syntax errors or violations of language-specific rules. Catching syntax errors early in the development process can save developers time and effort, preventing unexpected behavior and crashes during runtime. Most code analysis and linting tools, including ESLint and JSHint, provide built-in syntax checking capabilities.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.5 Code style enforcement<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Code style enforcement is the process of ensuring that code consistently adheres to a set of style guidelines. This can include aspects such as indentation, naming conventions, and the use of braces or semicolons. Consistent code style makes it easier for developers to read and understand each other&#8217;s code, improving collaboration and maintainability. Linting tools like ESLint, Prettier, and JSHint can help enforce code style rules automatically, reducing the need for manual adjustments and style-related discussions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. ESLint<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">2.1 Introduction and history<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">ESLint is a popular open-source linting tool for JavaScript and TypeScript that helps developers find and fix problems in their code. Created by Nicholas C. Zakas in 2013, ESLint was designed to be pluggable, meaning that developers can easily extend and customize it with their own rules and configurations. Over the years, ESLint has become the go-to choice for many developers, thanks to its flexibility, extensive rule set, and support for the latest ECMAScript features and popular JavaScript frameworks.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.2 Installation and setup<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">2.2.1 Global and local installation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">ESLint can be installed globally or locally in your project, depending on your needs. A global installation makes ESLint available across all projects on your system, while a local installation confines it to a specific project. It&#8217;s generally recommended to install ESLint locally to ensure that each project uses its own version and configuration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To install ESLint globally, run the following command:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">npm install -g eslint<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">To install ESLint locally in your project, navigate to the project&#8217;s root directory and run:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">npm install --save-dev eslint<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\">2.2.2 Configuration files<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">After installing ESLint, you&#8217;ll need to create a configuration file to define the rules and settings for your project. ESLint supports several configuration file formats, including <code><strong>.eslintrc.js<\/strong><\/code>, <code><strong>.eslintrc.cjs<\/strong><\/code>, <code><strong>.eslintrc.yaml<\/strong><\/code>, <code><strong>.eslintrc.yml<\/strong><\/code>, <code><strong>.eslintrc.json<\/strong><\/code>, and the <code><strong>eslintConfig<\/strong><\/code> field in your <code><strong>package.json<\/strong><\/code> file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To create an <code><strong>.eslintrc.js<\/strong><\/code> file, for example, run:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">touch .eslintrc.js<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Then, open the file and add your configuration:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">module<\/span>.exports = {\n  <span class=\"hljs-attr\">parserOptions<\/span>: {\n    <span class=\"hljs-attr\">ecmaVersion<\/span>: <span class=\"hljs-number\">2021<\/span>,\n    <span class=\"hljs-attr\">sourceType<\/span>: <span class=\"hljs-string\">\"module\"<\/span>,\n  },\n  <span class=\"hljs-attr\">env<\/span>: {\n    <span class=\"hljs-attr\">browser<\/span>: <span class=\"hljs-literal\">true<\/span>,\n    <span class=\"hljs-attr\">es2021<\/span>: <span class=\"hljs-literal\">true<\/span>,\n  },\n  <span class=\"hljs-attr\">rules<\/span>: {\n    <span class=\"hljs-string\">\"no-console\"<\/span>: <span class=\"hljs-string\">\"warn\"<\/span>,\n    <span class=\"hljs-string\">\"no-unused-vars\"<\/span>: <span class=\"hljs-string\">\"error\"<\/span>,\n  },\n};<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This configuration specifies the ECMAScript version and source type, sets the environment to browser and ES2021, and defines two basic rules: warning for <code>console<\/code> usage and throwing an error for unused variables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also extend popular configurations, like the ones provided by Airbnb or Google:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">module<\/span>.exports = {\n  <span class=\"hljs-attr\">extends<\/span>: &#91;<span class=\"hljs-string\">\"airbnb-base\"<\/span>, <span class=\"hljs-string\">\"prettier\"<\/span>],\n  <span class=\"hljs-attr\">rules<\/span>: {\n    <span class=\"hljs-comment\">\/\/ Add or override rules here<\/span>\n  },\n};<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">For more advanced configurations, consider using plugins, which allow you to include additional rules or support specific frameworks and libraries.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.3 Rules and plugins<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">ESLint provides a wide range of built-in rules, as well as the ability to add custom rules through plugins. This flexibility allows you to tailor the linting process to your project&#8217;s specific needs and coding standards.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2.3.1 Core rules<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">ESLint comes with a set of core rules that cover various aspects of code quality, including possible errors, best practices, stylistic issues, and ECMAScript 6+ features. You can browse the full list of core rules in the <a href=\"https:\/\/eslint.org\/docs\/rules\/\" target=\"_blank\" rel=\"noreferrer noopener\">ESLint documentation<\/a>. To enable or disable a rule, add it to the <code>rules<\/code> section of your configuration file and set its severity level (0: &#8220;off&#8221;, 1: &#8220;warn&#8221;, 2: &#8220;error&#8221;):<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">module<\/span>.exports = {\n  <span class=\"hljs-comment\">\/\/ ...<\/span>\n  <span class=\"hljs-attr\">rules<\/span>: {\n    <span class=\"hljs-string\">\"no-console\"<\/span>: <span class=\"hljs-string\">\"warn\"<\/span>,\n    <span class=\"hljs-string\">\"eqeqeq\"<\/span>: <span class=\"hljs-string\">\"error\"<\/span>,\n    <span class=\"hljs-string\">\"indent\"<\/span>: &#91;<span class=\"hljs-string\">\"error\"<\/span>, <span class=\"hljs-number\">2<\/span>],\n  },\n};<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In this example, the configuration warns when the <code><strong>console<\/strong><\/code> is used, requires strict equality checks (<code><strong>===<\/strong><\/code> and <code><strong>!==<\/strong><\/code>), and enforces an indentation of 2 spaces.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2.3.2 Plugin-specific rules<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Plugins are third-party extensions that provide additional rules or support for specific technologies, frameworks, and libraries. To use a plugin, you&#8217;ll need to install it as a dependency and include it in your configuration file. For example, to use the <code><strong>eslint-plugin-react<\/strong><\/code> plugin, you would first install it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">npm install --save-dev eslint-plugin-react<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Then, add the plugin to your ESLint configuration and enable its rules:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">module<\/span>.exports = {\n  <span class=\"hljs-comment\">\/\/ ...<\/span>\n  <span class=\"hljs-attr\">plugins<\/span>: &#91;<span class=\"hljs-string\">\"react\"<\/span>],\n  <span class=\"hljs-attr\">rules<\/span>: {\n    <span class=\"hljs-string\">\"react\/jsx-uses-vars\"<\/span>: <span class=\"hljs-string\">\"error\"<\/span>,\n    <span class=\"hljs-string\">\"react\/jsx-uses-react\"<\/span>: <span class=\"hljs-string\">\"error\"<\/span>,\n  },\n};<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\">2.3.3 Custom rules<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In addition to the core rules and plugin-specific rules, ESLint allows you to create your own custom rules. This can be useful when you need to enforce project-specific coding standards or check for domain-specific issues. To create a custom rule, you&#8217;ll need to write a rule definition in JavaScript and include it in your configuration file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, let&#8217;s create a custom rule that warns when a variable name contains the word &#8220;temp&#8221;:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create a new directory named <code><strong>rules<\/strong><\/code> in your project&#8217;s root folder:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">mkdir rules<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">2. Create a new JavaScript file for your custom rule, e.g., <code><strong>no-temp-vars.js<\/strong><\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">touch rules\/no-temp-vars.js<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">3. Open the file and define the rule:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">module<\/span>.exports = {\n  <span class=\"hljs-attr\">create<\/span>: <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">context<\/span>) <\/span>{\n    <span class=\"hljs-keyword\">return<\/span> {\n      <span class=\"hljs-attr\">VariableDeclarator<\/span>: <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">node<\/span>) <\/span>{\n        <span class=\"hljs-keyword\">if<\/span> (<span class=\"hljs-regexp\">\/temp\/i<\/span>.test(node.id.name)) {\n          context.report({\n            <span class=\"hljs-attr\">node<\/span>: node,\n            <span class=\"hljs-attr\">message<\/span>: <span class=\"hljs-string\">\"Variable name should not contain 'temp'\"<\/span>,\n          });\n        }\n      },\n    };\n  },\n};<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">4. Update your ESLint configuration file to include your custom rule:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">module<\/span>.exports = {\n  <span class=\"hljs-comment\">\/\/ ...<\/span>\n  <span class=\"hljs-attr\">rules<\/span>: {\n    <span class=\"hljs-comment\">\/\/ ...<\/span>\n    <span class=\"hljs-string\">\"no-temp-vars\"<\/span>: <span class=\"hljs-string\">\"warn\"<\/span>,\n  },\n  <span class=\"hljs-attr\">settings<\/span>: {\n    <span class=\"hljs-string\">\"rulesdir\"<\/span>: &#91;<span class=\"hljs-string\">\".\/rules\"<\/span>],\n  },\n};<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">With this custom rule in place, ESLint will warn you when it encounters a variable name containing the word &#8220;temp&#8221;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.4 Integrating with editors (VSCode, Sublime Text, etc.)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Integrating ESLint with your favorite code editor can help you catch issues and enforce coding standards in real-time, as you write your code. Most popular editors offer ESLint plugins or built-in support:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>VSCode<\/strong>: The <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=dbaeumer.vscode-eslint\" target=\"_blank\" rel=\"noreferrer noopener\">ESLint extension<\/a> for VSCode can be installed from the Visual Studio Marketplace. Once installed, it will automatically lint your JavaScript and TypeScript files based on your ESLint configuration.<\/li>\n\n\n\n<li><strong>Sublime Text<\/strong>: The <a href=\"https:\/\/packagecontrol.io\/packages\/SublimeLinter-eslint\" target=\"_blank\" rel=\"noreferrer noopener\">SublimeLinter-eslint<\/a> package can be installed using Package Control. Make sure you have <a href=\"https:\/\/packagecontrol.io\/packages\/SublimeLinter\">SublimeLinter<\/a> installed as well, as it&#8217;s a dependency.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2.5 Integrating with build tools (Webpack, Gulp, Grunt, etc.)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Integrating ESLint with your build tools can help ensure that your code meets your quality standards before deployment. Here are some examples of how to integrate ESLint with popular build tools:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Webpack<\/strong>: Use the <a href=\"https:\/\/github.com\/webpack-contrib\/eslint-webpack-plugin\" target=\"_blank\" rel=\"noreferrer noopener\">eslint-webpack-plugin<\/a> to lint your code during the build process. Install the plugin and add it to your <code><strong>webpack.config.js<\/strong><\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">npm install --save-dev eslint-webpack-plugin<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-comment\">\/\/ webpack.config.js<\/span>\n<span class=\"hljs-keyword\">const<\/span> ESLintPlugin = <span class=\"hljs-built_in\">require<\/span>(<span class=\"hljs-string\">\"eslint-webpack-plugin\"<\/span>);\n\n<span class=\"hljs-built_in\">module<\/span>.exports = {\n  <span class=\"hljs-comment\">\/\/ ...<\/span>\n  <span class=\"hljs-attr\">plugins<\/span>: &#91;<span class=\"hljs-keyword\">new<\/span> ESLintPlugin()],\n};<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>Gulp<\/strong>: Use the <a href=\"https:\/\/www.npmjs.com\/package\/gulp-eslint\" target=\"_blank\" rel=\"noreferrer noopener\">gulp-eslint<\/a> plugin to lint your code in a Gulp task:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">npm install --save-dev gulp-eslint\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-comment\">\/\/ gulpfile.js<\/span>\r\n<span class=\"hljs-keyword\">const<\/span> gulp = <span class=\"hljs-built_in\">require<\/span>(<span class=\"hljs-string\">\"gulp\"<\/span>);\r\n<span class=\"hljs-keyword\">const<\/span> eslint = <span class=\"hljs-built_in\">require<\/span>(<span class=\"hljs-string\">\"gulp-eslint\"<\/span>);\r\n\r\ngulp.task(<span class=\"hljs-string\">\"lint\"<\/span>, () =&gt; {\r\n  <span class=\"hljs-keyword\">return<\/span> gulp\r\n    .src(&#91;<span class=\"hljs-string\">\"src\/**\/*.js\"<\/span>])\r\n    .pipe(eslint())\r\n    .pipe(eslint.format())\r\n    .pipe(eslint.failAfterError());\r\n});\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>Grunt<\/strong>: Use the <a href=\"https:\/\/www.npmjs.com\/package\/grunt-eslint\" target=\"_blank\" rel=\"noreferrer noopener\">grunt-eslint<\/a> task to lint your code with Grunt:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">npm install --save-dev grunt-eslint\r<\/code><\/span><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-17\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-comment\">\/\/ Gruntfile.js<\/span>\r\n<span class=\"hljs-built_in\">module<\/span>.exports = <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">grunt<\/span>) <\/span>{\r\n  grunt.initConfig({\r\n    <span class=\"hljs-attr\">eslint<\/span>: {\r\n      <span class=\"hljs-attr\">target<\/span>: &#91;<span class=\"hljs-string\">\"src\/**\/*.js\"<\/span>],\r\n    },\r\n  });\r\n\r\n  grunt.loadNpmTasks(<span class=\"hljs-string\">\"grunt-eslint\"<\/span>);\r\n\r\n  grunt.registerTask(<span class=\"hljs-string\">\"default\"<\/span>, &#91;<span class=\"hljs-string\">\"eslint\"<\/span>]);\r\n};\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">2.6 Using with popular frameworks (React, Angular, Vue, etc.)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">ESLint can be easily integrated with popular JavaScript frameworks by using plugins and configurations tailored to each framework:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>React<\/strong>: Use the <a href=\"https:\/\/www.npmjs.com\/package\/eslint-plugin-react\">eslint-plugin-react<\/a> for React-specific linting rules. Install the plugin and include it in your ESLint configuration.<\/li>\n\n\n\n<li><strong>Angular<\/strong>: Use the <a href=\"https:\/\/www.npmjs.com\/package\/eslint-plugin-angular\">eslint-plugin-angular<\/a> for Angular-specific linting rules. Install the plugin and include it in your ESLint configuration.<\/li>\n\n\n\n<li><strong>Vue<\/strong>: Use the [eslint-plugin-vue](<a href=\"https:\/\/eslint.vuejs.org\/\">https:\/\/eslint.vuejs.org\/<\/a>) for Vue-specific linting rules. Install the plugin and include it in your ESLint configuration.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">3. Prettier<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">3.1 Introduction and history<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Prettier is an opinionated code formatter that aims to enforce consistent code style across your projects automatically. Created by James Long in 2017, Prettier supports a variety of languages, including JavaScript, TypeScript, HTML, CSS, and more. By focusing on formatting and not linting, Prettier complements tools like ESLint, which excel at analyzing code quality and enforcing best practices. Prettier has become increasingly popular among developers for its ease of use, automatic formatting, and ability to integrate with various code editors and build tools.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.2. Installation and setup<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">3.2.1. Global and local installation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Like ESLint, Prettier can be installed globally or locally in your project. A global installation makes Prettier available across all projects on your system, while a local installation confines it to a specific project. It&#8217;s generally recommended to install Prettier locally to ensure that each project uses its own version and configuration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To install Prettier globally, run the following command:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-18\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">npm install -g prettier\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-18\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">To install Prettier locally in your project, navigate to the project&#8217;s root directory and run:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">npm install --save-dev prettier\r<\/code><\/span><\/pre>\n\n\n<h4 class=\"wp-block-heading\">3.2.2. Configuration files<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">After installing Prettier, you&#8217;ll need to create a configuration file to define your preferred code style. Prettier supports several configuration file formats, including <code><strong>.prettierrc<\/strong><\/code>, <code><strong>.prettierrc.json<\/strong><\/code>, <code><strong>.prettierrc.yaml<\/strong><\/code>, <code><strong>.prettierrc.yml<\/strong><\/code>, <code><strong>.prettierrc.js<\/strong><\/code>, <code><strong>.prettierrc.toml<\/strong><\/code>, and the <code><strong>prettier<\/strong><\/code> field in your <code><strong>package.json<\/strong><\/code> file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To create a <code><strong>.prettierrc<\/strong><\/code> file, for example, run:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-19\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">touch .prettierrc\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-19\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Then, open the file and add your configuration:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-20\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"printWidth\"<\/span>: <span class=\"hljs-number\">80<\/span>,\r\n  <span class=\"hljs-attr\">\"tabWidth\"<\/span>: <span class=\"hljs-number\">2<\/span>,\r\n  <span class=\"hljs-attr\">\"useTabs\"<\/span>: <span class=\"hljs-literal\">false<\/span>,\r\n  <span class=\"hljs-attr\">\"semi\"<\/span>: <span class=\"hljs-literal\">true<\/span>,\r\n  <span class=\"hljs-attr\">\"singleQuote\"<\/span>: <span class=\"hljs-literal\">true<\/span>,\r\n  <span class=\"hljs-attr\">\"trailingComma\"<\/span>: <span class=\"hljs-string\">\"es5\"<\/span>,\r\n  <span class=\"hljs-attr\">\"bracketSpacing\"<\/span>: <span class=\"hljs-literal\">true<\/span>,\r\n  <span class=\"hljs-attr\">\"jsxBracketSameLine\"<\/span>: <span class=\"hljs-literal\">false<\/span>,\r\n  <span class=\"hljs-attr\">\"arrowParens\"<\/span>: <span class=\"hljs-string\">\"avoid\"<\/span>\r\n}\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-20\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This configuration specifies various formatting options, such as the maximum line width, tab width, whether to use tabs or spaces, semicolon usage, quote style, and more.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also create a <code><strong>.prettierignore<\/strong><\/code> file to specify files and directories that Prettier should ignore when formatting your code:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-21\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">touch<\/span> <span class=\"hljs-selector-class\">.prettierignore<\/span>\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-21\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Then, add patterns for files and directories to ignore:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">node_modules\/\r\ndist\/\r<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In this example, Prettier will ignore files in the <code><strong>node_modules<\/strong><\/code> and <code><strong>dist<\/strong><\/code> directories.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.4. Code formatting options<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Prettier provides various formatting options to help you enforce a consistent code style across your projects. Here are some of the most commonly used options:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Line length<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <code><strong>printWidth<\/strong><\/code> option controls the maximum line length. Prettier will wrap lines that exceed this limit. The default value is 80.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-22\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"printWidth\"<\/span>: <span class=\"hljs-number\">80<\/span>\r\n}\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-22\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\">Indentation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <code><strong>tabWidth<\/strong><\/code> option sets the number of spaces per indentation level. The default value is 2. You can also use the <code><strong>useTabs<\/strong><\/code> option to specify whether to use tabs for indentation instead of spaces. The default value is <code><strong>false<\/strong><\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-23\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"tabWidth\"<\/span>: <span class=\"hljs-number\">2<\/span>,\r\n  <span class=\"hljs-attr\">\"useTabs\"<\/span>: <span class=\"hljs-literal\">false<\/span>\r\n}\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-23\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\">Quotes<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <code><strong>singleQuote<\/strong><\/code> option controls whether single or double quotes are used in your code. When set to <code>true<\/code>, Prettier will use single quotes. The default value is <code><strong>false<\/strong><\/code>, which means double quotes are used by default.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-24\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"singleQuote\"<\/span>: <span class=\"hljs-literal\">true<\/span>\r\n}\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-24\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\">Semicolons<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <code><strong>semi<\/strong><\/code> option determines whether semicolons should be used to terminate statements. When set to <code><strong>true<\/strong><\/code>, Prettier will add semicolons; when set to <code><strong>false<\/strong><\/code>, Prettier will remove them. The default value is <code><strong>true<\/strong><\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-25\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"semi\"<\/span>: <span class=\"hljs-literal\">true<\/span>\r\n}\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-25\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\">Trailing commas<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <code><strong>trailingComma<\/strong><\/code> option controls the use of trailing commas in objects, arrays, and other data structures. Possible values are <code><strong>\"none\"<\/strong><\/code>, <code><strong>\"es5\"<\/strong><\/code>, and <code><strong>\"all\"<\/strong><\/code>. The default value is <code><strong>\"es5\"<\/strong><\/code>, which means trailing commas will be added where valid in ECMAScript 5.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-26\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"trailingComma\"<\/span>: <span class=\"hljs-string\">\"es5\"<\/span>\r\n}\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-26\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\">Other formatting options<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Prettier provides several additional formatting options to fine-tune your code style:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code><strong>bracketSpacing<\/strong><\/code>: Controls the spacing between brackets in object literals. The default value is <code>true<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-27\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"bracketSpacing\"<\/span>: <span class=\"hljs-literal\">true<\/span>\r\n}\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-27\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><code><strong>jsxBracketSameLine<\/strong><\/code>: Determines whether the closing bracket of a JSX element should be on the same line as the last attribute or a new line. The default value is <code><strong>false<\/strong><\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-28\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"jsxBracketSameLine\"<\/span>: <span class=\"hljs-literal\">false<\/span>\r\n}\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-28\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><code><strong>arrowParens<\/strong><\/code>: Controls the use of parentheses around single-parameter arrow function arguments. Possible values are <code><strong>\"always\"<\/strong><\/code> (use parentheses) and <code><strong>\"avoid\"<\/strong><\/code> (omit parentheses when possible). The default value is <code><strong>\"always\"<\/strong><\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-29\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"arrowParens\"<\/span>: <span class=\"hljs-string\">\"avoid\"<\/span>\r\n}\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-29\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">For a complete list of formatting options, refer to the <a href=\"https:\/\/prettier.io\/docs\/en\/options.html\" target=\"_blank\" rel=\"noreferrer noopener\">Prettier documentation<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.5 Integrating with editors (VSCode, Sublime Text, etc.)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Prettier can be easily integrated with most popular code editors to automatically format your code as you write. Here&#8217;s how to integrate Prettier with some popular editors:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>VSCode<\/strong>: The <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=esbenp.prettier-vscode\" target=\"_blank\" rel=\"noreferrer noopener\">Prettier &#8211; Code formatter<\/a> extension can be installed from the Visual Studio Marketplace. Once installed, you can configure the extension to format your code on save or by using a keyboard shortcut. To set Prettier as the default formatter, add the following settings to your VSCode configuration:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-30\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"editor.defaultFormatter\"<\/span>: <span class=\"hljs-string\">\"esbenp.prettier-vscode\"<\/span>,\r\n  <span class=\"hljs-attr\">\"editor.formatOnSave\"<\/span>: <span class=\"hljs-literal\">true<\/span>\r\n}\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-30\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>Sublime Text<\/strong>: The <a href=\"https:\/\/packagecontrol.io\/packages\/JsPrettier\">JsPrettier<\/a> package can be installed using Package Control. After installation, you can configure the package to format your code on save or by using a keyboard shortcut. To enable format on save, add the following to your JsPrettier settings:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-31\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\n  <span class=\"hljs-attr\">\"auto_format_on_save\"<\/span>: <span class=\"hljs-literal\">true<\/span>\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-31\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">3.6 Integrating with build tools (Webpack, Gulp, Grunt, etc.)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can also integrate Prettier with your build tools to automatically format your code during the build process. Here are some examples for popular build tools:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Webpack<\/strong>: Use the <a href=\"https:\/\/www.npmjs.com\/package\/prettier-webpack-plugin\" target=\"_blank\" rel=\"noreferrer noopener\">prettier-webpack-plugin<\/a> to format your code during the build process:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-32\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">npm install --save-dev prettier-webpack-plugin\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-32\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-33\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-comment\">\/\/ webpack.config.js<\/span>\r\n<span class=\"hljs-keyword\">const<\/span> PrettierPlugin = <span class=\"hljs-built_in\">require<\/span>(<span class=\"hljs-string\">\"prettier-webpack-plugin\"<\/span>);\r\n\r\n<span class=\"hljs-built_in\">module<\/span>.exports = {\r\n  <span class=\"hljs-comment\">\/\/ ...<\/span>\r\n  <span class=\"hljs-attr\">plugins<\/span>: &#91;<span class=\"hljs-keyword\">new<\/span> PrettierPlugin()],\r\n};\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-33\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>Gulp<\/strong>: Use the <a href=\"https:\/\/www.npmjs.com\/package\/gulp-prettier\">gulp-prettier<\/a> plugin to format your code in a Gulp task:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-34\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">npm install --save-dev gulp-prettier<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-34\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-35\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-comment\">\/\/ gulpfile.js<\/span>\r\n<span class=\"hljs-keyword\">const<\/span> gulp = <span class=\"hljs-built_in\">require<\/span>(<span class=\"hljs-string\">\"gulp\"<\/span>);\r\n<span class=\"hljs-keyword\">const<\/span> prettier = <span class=\"hljs-built_in\">require<\/span>(<span class=\"hljs-string\">\"gulp-prettier\"<\/span>);\r\n\r\ngulp.task(<span class=\"hljs-string\">\"prettier\"<\/span>, () =&gt; {\r\n  <span class=\"hljs-keyword\">return<\/span> gulp\r\n    .src(&#91;<span class=\"hljs-string\">\"src\/**\/*.js\"<\/span>])\r\n    .pipe(prettier())\r\n    .pipe(gulp.dest(<span class=\"hljs-string\">\"src\"<\/span>));\r\n});\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-35\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>Grunt<\/strong>: Use the <a href=\"https:\/\/www.npmjs.com\/package\/grunt-prettier\" target=\"_blank\" rel=\"noreferrer noopener\">grunt-prettier<\/a> task to format your code with Grunt:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-36\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">npm install --save-dev grunt-prettier\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-36\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-37\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-comment\">\/\/ Gruntfile.js<\/span>\r\n<span class=\"hljs-built_in\">module<\/span>.exports = <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">grunt<\/span>) <\/span>{\r\n  grunt.initConfig({\r\n    <span class=\"hljs-attr\">prettier<\/span>: {\r\n      <span class=\"hljs-attr\">options<\/span>: {\r\n        <span class=\"hljs-comment\">\/\/ Task-specific options go here.<\/span>\r\n      },\r\n      <span class=\"hljs-attr\">your_target<\/span>: {\r\n        <span class=\"hljs-attr\">src<\/span>: &#91;<span class=\"hljs-string\">\"src\/**\/*.js\"<\/span>],\r\n      },\r\n    },\r\n  });\r\n\r\n  grunt.loadNpmTasks(<span class=\"hljs-string\">\"grunt-prettier\"<\/span>);\r\n\r\n  grunt.registerTask(<span class=\"hljs-string\">\"default\"<\/span>, &#91;<span class=\"hljs-string\">\"prettier\"<\/span>]);\r\n};\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-37\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">3.7 Using with popular frameworks (React, Angular, Vue, etc.)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Prettier can be easily integrated with popular JavaScript frameworks such as React, Angular, and Vue. Here&#8217;s how to configure Prettier for each framework:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>React<\/strong>: Prettier supports JSX out of the box, so no additional configuration is needed for React projects. Just ensure that the <code><strong>parser<\/strong><\/code> option is set to <code><strong>\"babel\"<\/strong><\/code> (default) or <code><strong>\"typescript\"<\/strong><\/code> if you&#8217;re using TypeScript:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-38\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"parser\"<\/span>: <span class=\"hljs-string\">\"babel\"<\/span>\r\n}\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-38\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>Angular<\/strong>: Prettier can format Angular templates and TypeScript code. Set the <code><strong>parser<\/strong><\/code> option to <code><strong>\"angular\"<\/strong><\/code> for HTML templates and <code><strong>\"typescript\"<\/strong><\/code> for TypeScript files:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-39\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"overrides\"<\/span>: &#91;\r\n    {\r\n      <span class=\"hljs-attr\">\"files\"<\/span>: <span class=\"hljs-string\">\"*.component.html\"<\/span>,\r\n      <span class=\"hljs-attr\">\"options\"<\/span>: { <span class=\"hljs-attr\">\"parser\"<\/span>: <span class=\"hljs-string\">\"angular\"<\/span> }\r\n    },\r\n    {\r\n      <span class=\"hljs-attr\">\"files\"<\/span>: <span class=\"hljs-string\">\"*.ts\"<\/span>,\r\n      <span class=\"hljs-attr\">\"options\"<\/span>: { <span class=\"hljs-attr\">\"parser\"<\/span>: <span class=\"hljs-string\">\"typescript\"<\/span> }\r\n    }\r\n  ]\r\n}\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-39\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>Vue<\/strong>: Prettier can format Vue single-file components by using the <code><strong>@prettier\/plugin-vue<\/strong><\/code> package:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-40\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">npm install --save-dev @prettier\/plugin-vue\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-40\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In your Prettier configuration, set the <code><strong>parser<\/strong><\/code> option to <code><strong>\"vue\"<\/strong><\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-41\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"parser\"<\/span>: <span class=\"hljs-string\">\"vue\"<\/span>\r\n}\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-41\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">4. JSHint<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">4.1. Introduction and history<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">JSHint is a popular static code analysis tool for JavaScript that helps developers find potential errors and maintain a consistent code style. It was created by Anton Kovalyov in 2011 as a fork of the JSLint project, which was developed by Douglas Crockford. JSHint was initially designed to be more flexible and less opinionated than JSLint, allowing developers to enforce their own coding standards.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Over the years, JSHint has gained a substantial following among JavaScript developers. However, with the introduction of more modern and customizable tools like ESLint and Prettier, its popularity has somewhat diminished.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.2 Installation and setup<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">4.2.1 Global and local installation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">You can install JSHint globally or locally, depending on your project requirements. To install it globally, run the following command:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-42\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">npm install -g jshint\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-42\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">To install JSHint locally in your project, navigate to your project&#8217;s root directory and run:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-43\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">npm install --save-dev jshint<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-43\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\">4.2.2 Configuration files<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">JSHint uses configuration files to specify the rules and settings for your project. The configuration file is named <code><strong>.jshintrc<\/strong><\/code> and should be placed in the root directory of your project. You can also place this file in any subdirectory if you want to enforce different rules for specific parts of your project.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A typical <code><strong>.jshintrc<\/strong><\/code> file contains a JSON object that specifies the rules and options for JSHint. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-44\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"undef\"<\/span>: <span class=\"hljs-literal\">true<\/span>,\r\n  <span class=\"hljs-attr\">\"unused\"<\/span>: <span class=\"hljs-literal\">true<\/span>,\r\n  <span class=\"hljs-attr\">\"globals\"<\/span>: {\r\n    <span class=\"hljs-attr\">\"jQuery\"<\/span>: <span class=\"hljs-literal\">true<\/span>,\r\n    <span class=\"hljs-attr\">\"console\"<\/span>: <span class=\"hljs-literal\">true<\/span>\r\n  }\r\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-44\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In this example, the <code><strong>undef<\/strong><\/code> option requires that all variables be defined before they are used, and the <code><strong>unused<\/strong><\/code> option warns about unused variables. The <code><strong>globals<\/strong><\/code> object defines global variables that are allowed to be used without being defined in the current file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a complete list of JSHint options, refer to the <a href=\"https:\/\/jshint.com\/docs\/options\/\" target=\"_blank\" rel=\"noreferrer noopener\">JSHint documentation<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.3 Rules and options<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">JSHint provides various rules and options that can be grouped into three categories: enforcing options, relaxing options, and environment options. By configuring these options in your <code><strong>.jshintrc<\/strong><\/code> file, you can tailor JSHint to meet your project&#8217;s specific needs.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4.3.1 Enforcing options<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Enforcing options are used to set strict rules that help maintain code quality and catch potential errors. Some examples of enforcing options include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>bitwise<\/strong><\/code>: Requires the use of bitwise operators to be explicitly allowed (e.g., <code>&amp;<\/code>, <code>|<\/code>, <code>^<\/code>, etc.).<\/li>\n\n\n\n<li><code><strong>curly<\/strong><\/code>: Requires the use of curly braces around all block statements (e.g., <code>if<\/code>, <code>while<\/code>, <code>for<\/code>, etc.).<\/li>\n\n\n\n<li><code><strong>eqeqeq<\/strong><\/code>: Requires the use of <code>===<\/code> and <code>!==<\/code> instead of <code>==<\/code> and <code>!=<\/code>.<\/li>\n\n\n\n<li><code><strong>noarg<\/strong><\/code>: Prohibits the use of the <code><strong>arguments.caller<\/strong><\/code> and <code><strong>arguments.callee<\/strong><\/code> properties.<\/li>\n\n\n\n<li><code><strong>undef<\/strong><\/code>: Requires all variables to be defined before they are used.<\/li>\n\n\n\n<li><code><strong>unused<\/strong><\/code>: Warns about unused variables.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">4.3.2 Relaxing options<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Relaxing options allow you to loosen certain strict rules to accommodate specific coding styles or practices. Some examples of relaxing options include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>asi<\/strong><\/code>: Allows the omission of semicolons when they are not required by JavaScript&#8217;s automatic semicolon insertion (ASI) rules.<\/li>\n\n\n\n<li><code><strong>boss<\/strong><\/code>: Allows assignments in conditional expressions (e.g., <code>if (a = 10) { ... }<\/code>).<\/li>\n\n\n\n<li><code><strong>eqnull<\/strong><\/code>: Allows the use of <code>== null<\/code> to check for <code>null<\/code> or <code>undefined<\/code>.<\/li>\n\n\n\n<li><code><strong>expr<\/strong><\/code>: Allows the use of expressions where a statement is expected (e.g., <code>a || b();<\/code>).<\/li>\n\n\n\n<li><code><strong>loopfunc<\/strong><\/code>: Allows the use of functions inside loops, which can sometimes lead to unintended behavior due to variable scoping issues.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">4.3.3 Environment options<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Environment options define global variables and behaviors specific to certain runtime environments. By setting these options, you can inform JSHint about the environment your code will be running in. Some examples of environment options include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>browser<\/strong><\/code>: Indicates that the code will run in a browser environment, allowing global variables like <code>window<\/code>, <code>document<\/code>, and <code>navigator<\/code>.<\/li>\n\n\n\n<li><code><strong>node<\/strong><\/code>: Indicates that the code will run in a Node.js environment, allowing global variables like <code>require<\/code>, <code>module<\/code>, and <code>process<\/code>.<\/li>\n\n\n\n<li><code><strong>jquery<\/strong><\/code>: Indicates that the jQuery library is being used, allowing global variables like <code>jQuery<\/code> and <code>$<\/code>.<\/li>\n\n\n\n<li><code><strong>mocha<\/strong><\/code>: Indicates that the code will run in the Mocha testing framework, allowing global variables like <code>describe<\/code>, <code>it<\/code>, and <code>beforeEach<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">By combining enforcing options, relaxing options, and environment options in your <code><strong>.jshintrc<\/strong><\/code> file, you can create a customized set of rules that help maintain code quality and consistency in your JavaScript projects.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.4 Integrating with editors (VSCode, Sublime Text, etc.)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">JSHint can be integrated with popular code editors to provide real-time feedback and linting as you write code. Here&#8217;s how to set up JSHint with some common editors:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>VSCode<\/strong>: Install the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=dbaeumer.jshint\">JSHint extension<\/a> from the Visual Studio Code marketplace. Once installed, JSHint will automatically lint your JavaScript files based on your <code>.jshintrc<\/code> configuration.<\/li>\n\n\n\n<li><strong>Sublime Text<\/strong>: Install the <a href=\"https:\/\/packagecontrol.io\/packages\/SublimeLinter-jshint\">SublimeLinter-jshint<\/a> package using Package Control. This package requires the <a href=\"https:\/\/packagecontrol.io\/packages\/SublimeLinter\">SublimeLinter<\/a> package to work. Once installed, JSHint will lint your JavaScript files based on your <code>.jshintrc<\/code> configuration.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4.5 Integrating with build tools (Webpack, Gulp, Grunt, etc.)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">JSHint can be integrated with build tools like Webpack, Gulp, and Grunt to enforce code quality during the build process. Here&#8217;s how to set up JSHint with some common build tools:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Webpack<\/strong>: Use the <a href=\"https:\/\/github.com\/webpack-contrib\/jshint-loader\">jshint-loader<\/a> to integrate JSHint with Webpack. Add the <code><strong>jshint-loader<\/strong><\/code> to your <code><strong>module.rules<\/strong><\/code> in your <code><strong>webpack.config.js<\/strong><\/code> file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-45\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">module<\/span>.exports = {\r\n  <span class=\"hljs-comment\">\/\/ ...<\/span>\r\n  <span class=\"hljs-attr\">module<\/span>: {\r\n    <span class=\"hljs-attr\">rules<\/span>: &#91;\r\n      {\r\n        <span class=\"hljs-attr\">test<\/span>: <span class=\"hljs-regexp\">\/\\.js$\/<\/span>,\r\n        <span class=\"hljs-attr\">exclude<\/span>: <span class=\"hljs-regexp\">\/node_modules\/<\/span>,\r\n        <span class=\"hljs-attr\">use<\/span>: &#91;<span class=\"hljs-string\">'jshint-loader'<\/span>],\r\n      },\r\n    ],\r\n  },\r\n};\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-45\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>Gulp<\/strong>: Use the <a href=\"https:\/\/www.npmjs.com\/package\/gulp-jshint\">gulp-jshint<\/a> plugin to integrate JSHint with Gulp. Add a task in your <code>gulpfile.js<\/code> to run JSHint on your JavaScript files:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-46\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">const<\/span> gulp = <span class=\"hljs-keyword\">require<\/span>(<span class=\"hljs-string\">'gulp'<\/span>);\r\n<span class=\"hljs-keyword\">const<\/span> jshint = <span class=\"hljs-keyword\">require<\/span>(<span class=\"hljs-string\">'gulp-jshint'<\/span>);\r\n\r\ngulp.task(<span class=\"hljs-string\">'lint'<\/span>, () =&gt; {\r\n  <span class=\"hljs-keyword\">return<\/span> gulp\r\n    .src(<span class=\"hljs-string\">'src\/**\/*.js'<\/span>)\r\n    .pipe(jshint())\r\n    .pipe(jshint.reporter(<span class=\"hljs-string\">'default'<\/span>));\r\n});\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-46\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>Grunt<\/strong>: Use the <a href=\"https:\/\/www.npmjs.com\/package\/grunt-contrib-jshint\">grunt-contrib-jshint<\/a> plugin to integrate JSHint with Grunt. Add a task in your <code><strong>Gruntfile.js<\/strong><\/code> to run JSHint on your JavaScript files:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-47\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">module<\/span>.exports = <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">grunt<\/span>) <\/span>{\r\n  grunt.initConfig({\r\n    <span class=\"hljs-attr\">jshint<\/span>: {\r\n      <span class=\"hljs-attr\">files<\/span>: &#91;<span class=\"hljs-string\">'src\/**\/*.js'<\/span>],\r\n    },\r\n  });\r\n\r\n  grunt.loadNpmTasks(<span class=\"hljs-string\">'grunt-contrib-jshint'<\/span>);\r\n\r\n  grunt.registerTask(<span class=\"hljs-string\">'default'<\/span>, &#91;<span class=\"hljs-string\">'jshint'<\/span>]);\r\n};\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-47\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">4.6 Using with popular frameworks (React, Angular, Vue, etc.)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">JSHint can be used with popular JavaScript frameworks like React, Angular, and Vue. However, since JSHint does not have built-in support for JSX or advanced static analysis capabilities, it may not be the best choice for linting modern JavaScript frameworks. ESLint, in combination with Prettier, is often a more suitable option for these projects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Choosing the Right Tool<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">5.1 Pros and cons of each tool<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>JSHint<\/strong>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pros:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Simple and easy to set up.<\/li>\n\n\n\n<li>Good for enforcing basic code quality and consistency.<\/li>\n\n\n\n<li>Lightweight and fast.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Cons:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Limited in terms of extensibility and customization.<\/li>\n\n\n\n<li>Lacks support for JSX and modern JavaScript features.<\/li>\n\n\n\n<li>Less popular and widely used compared to ESLint and Prettier.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>ESLint<\/strong>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pros:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Highly extensible and customizable with a wide range of built-in rules.<\/li>\n\n\n\n<li>Support for custom rules and plugins, making it adaptable to various project requirements.<\/li>\n\n\n\n<li>Compatible with modern JavaScript features, frameworks, and libraries.<\/li>\n\n\n\n<li>Actively maintained and widely used by the community.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Cons:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Can be more complex to set up and configure compared to JSHint.<\/li>\n\n\n\n<li>Slower than JSHint due to its extensive rule set and additional features.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Prettier<\/strong>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pros:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Automatically formats code for consistency and readability.<\/li>\n\n\n\n<li>Integrates well with ESLint and various editors and build tools.<\/li>\n\n\n\n<li>Supports modern JavaScript features, JSX, and other languages like TypeScript, HTML, and CSS.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Cons:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Focused on code formatting, not linting or error detection.<\/li>\n\n\n\n<li>Opinionated with limited configuration options.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">5.2 Using ESLint and Prettier together<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Using ESLint and Prettier together provides a comprehensive solution for both linting and code formatting. ESLint handles linting tasks and enforces coding standards, while Prettier takes care of code formatting.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To use ESLint and Prettier together, follow these steps:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Install ESLint and Prettier along with the required plugins:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-48\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">npm install --save-dev eslint prettier eslint-config-prettier eslint-plugin-prettier\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-48\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">2. Create an <code><strong>.eslintrc<\/strong><\/code> file in your project&#8217;s root directory and extend the <code><strong>prettier<\/strong><\/code> configuration:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-49\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"extends\"<\/span>: &#91;<span class=\"hljs-string\">\"prettier\"<\/span>]\r\n}\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-49\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">3. Add the <code><strong>prettier<\/strong><\/code> plugin and rule to your ESLint configuration:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-50\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\">{\r\n  <span class=\"hljs-attr\">\"plugins\"<\/span>: &#91;<span class=\"hljs-string\">\"prettier\"<\/span>],\r\n  <span class=\"hljs-attr\">\"rules\"<\/span>: {\r\n    <span class=\"hljs-attr\">\"prettier\/prettier\"<\/span>: <span class=\"hljs-string\">\"error\"<\/span>\r\n  }\r\n}\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-50\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">4. Configure Prettier by creating a <code><strong>.prettierrc<\/strong><\/code> file in your project&#8217;s root directory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5.3 Deciding factors for choosing a tool<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Project requirements<\/strong>: Consider the specific needs of your project, such as language features, frameworks, and libraries. ESLint is more suitable for projects that require extensive customization and support for modern JavaScript features.<\/li>\n\n\n\n<li><strong>Team preferences<\/strong>: Take into account your team&#8217;s coding style, preferences, and familiarity with different tools. Using a tool that the team is comfortable with can improve productivity and code quality.<\/li>\n\n\n\n<li><strong>Existing codebase<\/strong>: If you are working with an existing codebase, consider whether it already uses one of these tools. If so, it may be more efficient to continue using the same tool or migrate to a new one if there are clear advantages.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Code analysis and linting play a critical role in JavaScript development by helping developers identify and fix potential issues early in the development process. These tools enforce coding standards, improve code quality, and maintain a consistent code style across projects. With the growing complexity of JavaScript applications and the increasing number of developers collaborating on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[7,4],"tags":[],"class_list":["post-253","post","type-post","status-publish","format-standard","category-javascript","category-programming-languages","entry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JavaScript Code Analysis and Linting: ESLint, Prettier, and JSHint<\/title>\n<meta name=\"description\" content=\"Code analysis and linting play a critical role in JavaScript development by helping developers identify and fix potential issues early in the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.w3computing.com\/articles\/javascript-code-analysis-linting-eslint-prettier-jshint\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Code Analysis and Linting: ESLint, Prettier, and JSHint\" \/>\n<meta property=\"og:description\" content=\"Code analysis and linting play a critical role in JavaScript development by helping developers identify and fix potential issues early in the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.w3computing.com\/articles\/javascript-code-analysis-linting-eslint-prettier-jshint\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-12T20:23:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-23T16:22:00+00:00\" \/>\n<meta name=\"author\" content=\"w3compadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"w3compadmin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/javascript-code-analysis-linting-eslint-prettier-jshint\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/javascript-code-analysis-linting-eslint-prettier-jshint\\\/\"},\"author\":{\"name\":\"w3compadmin\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#\\\/schema\\\/person\\\/a550b3e20d78bb4f79b7c6b7b53f0561\"},\"headline\":\"JavaScript Code Analysis and Linting: ESLint, Prettier, and JSHint\",\"datePublished\":\"2023-04-12T20:23:07+00:00\",\"dateModified\":\"2023-08-23T16:22:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/javascript-code-analysis-linting-eslint-prettier-jshint\\\/\"},\"wordCount\":3475,\"commentCount\":0,\"articleSection\":[\"JavaScript\",\"Programming Languages\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/javascript-code-analysis-linting-eslint-prettier-jshint\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/javascript-code-analysis-linting-eslint-prettier-jshint\\\/\",\"url\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/javascript-code-analysis-linting-eslint-prettier-jshint\\\/\",\"name\":\"JavaScript Code Analysis and Linting: ESLint, Prettier, and JSHint\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#website\"},\"datePublished\":\"2023-04-12T20:23:07+00:00\",\"dateModified\":\"2023-08-23T16:22:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#\\\/schema\\\/person\\\/a550b3e20d78bb4f79b7c6b7b53f0561\"},\"description\":\"Code analysis and linting play a critical role in JavaScript development by helping developers identify and fix potential issues early in the\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/javascript-code-analysis-linting-eslint-prettier-jshint\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/javascript-code-analysis-linting-eslint-prettier-jshint\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/javascript-code-analysis-linting-eslint-prettier-jshint\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Articles Home\",\"item\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Programming Languages\",\"item\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/programming-languages\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript Code Analysis and Linting: ESLint, Prettier, and JSHint\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#website\",\"url\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/\",\"name\":\"Developer Articles Hub\",\"description\":\"\",\"alternateName\":\"Developer Articles\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#\\\/schema\\\/person\\\/a550b3e20d78bb4f79b7c6b7b53f0561\",\"name\":\"w3compadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/wp-content\\\/litespeed\\\/avatar\\\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266\",\"url\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/wp-content\\\/litespeed\\\/avatar\\\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266\",\"contentUrl\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/wp-content\\\/litespeed\\\/avatar\\\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266\",\"caption\":\"w3compadmin\"},\"sameAs\":[\"http:\\\/\\\/w3computing.com\\\/articles\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript Code Analysis and Linting: ESLint, Prettier, and JSHint","description":"Code analysis and linting play a critical role in JavaScript development by helping developers identify and fix potential issues early in the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.w3computing.com\/articles\/javascript-code-analysis-linting-eslint-prettier-jshint\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Code Analysis and Linting: ESLint, Prettier, and JSHint","og_description":"Code analysis and linting play a critical role in JavaScript development by helping developers identify and fix potential issues early in the","og_url":"https:\/\/www.w3computing.com\/articles\/javascript-code-analysis-linting-eslint-prettier-jshint\/","article_published_time":"2023-04-12T20:23:07+00:00","article_modified_time":"2023-08-23T16:22:00+00:00","author":"w3compadmin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"w3compadmin","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.w3computing.com\/articles\/javascript-code-analysis-linting-eslint-prettier-jshint\/#article","isPartOf":{"@id":"https:\/\/www.w3computing.com\/articles\/javascript-code-analysis-linting-eslint-prettier-jshint\/"},"author":{"name":"w3compadmin","@id":"https:\/\/www.w3computing.com\/articles\/#\/schema\/person\/a550b3e20d78bb4f79b7c6b7b53f0561"},"headline":"JavaScript Code Analysis and Linting: ESLint, Prettier, and JSHint","datePublished":"2023-04-12T20:23:07+00:00","dateModified":"2023-08-23T16:22:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.w3computing.com\/articles\/javascript-code-analysis-linting-eslint-prettier-jshint\/"},"wordCount":3475,"commentCount":0,"articleSection":["JavaScript","Programming Languages"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.w3computing.com\/articles\/javascript-code-analysis-linting-eslint-prettier-jshint\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.w3computing.com\/articles\/javascript-code-analysis-linting-eslint-prettier-jshint\/","url":"https:\/\/www.w3computing.com\/articles\/javascript-code-analysis-linting-eslint-prettier-jshint\/","name":"JavaScript Code Analysis and Linting: ESLint, Prettier, and JSHint","isPartOf":{"@id":"https:\/\/www.w3computing.com\/articles\/#website"},"datePublished":"2023-04-12T20:23:07+00:00","dateModified":"2023-08-23T16:22:00+00:00","author":{"@id":"https:\/\/www.w3computing.com\/articles\/#\/schema\/person\/a550b3e20d78bb4f79b7c6b7b53f0561"},"description":"Code analysis and linting play a critical role in JavaScript development by helping developers identify and fix potential issues early in the","breadcrumb":{"@id":"https:\/\/www.w3computing.com\/articles\/javascript-code-analysis-linting-eslint-prettier-jshint\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.w3computing.com\/articles\/javascript-code-analysis-linting-eslint-prettier-jshint\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.w3computing.com\/articles\/javascript-code-analysis-linting-eslint-prettier-jshint\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Articles Home","item":"https:\/\/www.w3computing.com\/articles\/"},{"@type":"ListItem","position":2,"name":"Programming Languages","item":"https:\/\/www.w3computing.com\/articles\/programming-languages\/"},{"@type":"ListItem","position":3,"name":"JavaScript Code Analysis and Linting: ESLint, Prettier, and JSHint"}]},{"@type":"WebSite","@id":"https:\/\/www.w3computing.com\/articles\/#website","url":"https:\/\/www.w3computing.com\/articles\/","name":"Developer Articles Hub","description":"","alternateName":"Developer Articles","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.w3computing.com\/articles\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.w3computing.com\/articles\/#\/schema\/person\/a550b3e20d78bb4f79b7c6b7b53f0561","name":"w3compadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.w3computing.com\/articles\/wp-content\/litespeed\/avatar\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266","url":"https:\/\/www.w3computing.com\/articles\/wp-content\/litespeed\/avatar\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266","contentUrl":"https:\/\/www.w3computing.com\/articles\/wp-content\/litespeed\/avatar\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266","caption":"w3compadmin"},"sameAs":["http:\/\/w3computing.com\/articles"]}]}},"featured_image_src":null,"featured_image_src_square":null,"author_info":{"display_name":"w3compadmin","author_link":"https:\/\/www.w3computing.com\/articles\/author\/w3compadmin\/"},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/comments?post=253"}],"version-history":[{"count":5,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts\/253\/revisions"}],"predecessor-version":[{"id":259,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts\/253\/revisions\/259"}],"wp:attachment":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/media?parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/categories?post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/tags?post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}