Skip to content

Commit

Permalink
Merge pull request #223 from palantirnet/dev-37-eslint
Browse files Browse the repository at this point in the history
DEV-37: Lint custom javascript with eslint
  • Loading branch information
byrond authored Aug 16, 2023
2 parents ce5fa0b + 6bcfd92 commit 5d7da7e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
18 changes: 18 additions & 0 deletions defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,21 @@ styleguide:
root: 'styleguide'
# Command to compile the style guide assets, for use during the build and artifact steps.
command: 'yarn default'

# Configuration for linting custom javascript.
#
# Update these properties to reflect the directories and extensions used for
# your project's custom javascript.
# @see https://eslint.org/docs/latest/use/core-concepts
eslint:
# Run eslint on custom modules AND themes, this must be a single value.
# @see: https://eslint.org/docs/latest/use/command-line-interface#run-the-cli
#
# If you need multiple directories that don't match a single pattern, you
# may need to add multiple config values here and add a for loop to the build
# target for eslint.
directory: "${drupal.root}/**/custom/"
# Run eslint on files with .es6.js extension.
# This can be a comma separated list.
# @see: https://eslint.org/docs/latest/use/command-line-interface#--ext
extensions: ".es6.js"
36 changes: 36 additions & 0 deletions defaults/install/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@
<!-- Run Drupal Check. -->
<foreach list="${drupal-check.directories}" param="drupal-check.dir" target="drupal-check" />

<!-- Run eslint -->
<phingcall target="eslint" />

<!-- Ensure the composer.lock file is up to date -->
<exec command="composer validate --no-check-all --no-check-publish" logoutput="true" checkreturn="true" />
</target>
Expand All @@ -143,6 +146,13 @@
<exec command="${drupal-check.command}" logoutput="true" checkreturn="true" />
</target>

<!-- Target: eslint -->
<target name="eslint" depends="install-node-dependencies">
<!-- Lint custom module and theme (by default) javascript. -->
<echo msg="$> yarn run eslint --ext ${eslint.extensions} ${eslint.directory}" />
<exec command="yarn run eslint --fix-dry-run --ext ${eslint.extensions} --resolve-plugins-relative-to ${drupal.root}/core --no-error-on-unmatched-pattern ${eslint.directory}" logoutput="true" checkreturn="true" />
</target>


<!-- Target: code-fix -->
<target name="code-fix" description="Run the automated code fixer.">
Expand All @@ -151,6 +161,32 @@
<exec command="vendor/bin/phpcbf" logoutput="true" checkreturn="false" />
</target>

<!-- Target: install-node-dependencies -->
<target name="install-node-dependencies" depends="" description="Install project, core, and custom module node dependencies">
<echo msg="Seeing if project npm packages are installed and at the expected version." />
<exec command="yarn install --check-files --verbose" returnProperty="project_dependencies" logoutput="true" />
<if>
<not>
<equals arg1="${project_dependencies}" arg2="0" />
</not>
<then>
<echo msg="Install project node dependencies to get eslint libraries." />
<exec dir="${drupal.root}/.." command="yarn install" logoutput="true" />
</then>
</if>
<echo msg="Seeing if Drupal core npm packages are installed and at the expected version." />
<exec dir="${drupal.root}/core" command="yarn install --check-files --verbose" returnProperty="core_dependencies" logoutput="true" />
<if>
<not>
<equals arg1="${core_dependencies}" arg2="0" />
</not>
<then>
<echo msg="Install Core node dependencies to get eslint libraries." />
<exec dir="${drupal.root}/core" command="yarn install" logoutput="true" checkreturn="true" />
</then>
</if>
</target>


<!-- Target: artifact -->
<target name="artifact" description="Build and deploy the application.">
Expand Down
2 changes: 1 addition & 1 deletion defaults/install/phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<config name="ignore_errors_on_exit" value="0" />

<!-- Set extensions to scan. -->
<arg name="extensions" value="php,module,inc,install,test,profile,theme,info,yml,css,js"/>
<arg name="extensions" value="php,module,inc,install,test,profile,theme,info,yml,css"/>

<!-- Use colors in output. -->
<arg name="colors"/>
Expand Down

0 comments on commit 5d7da7e

Please sign in to comment.