| 1 | package Code::TidyAll::Plugin::JSHint; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Specio::Library::String; | ||
| 7 | |||
| 8 | use Moo; | ||
| 9 | |||
| 10 | extends 'Code::TidyAll::Plugin'; | ||
| 11 | |||
| 12 | has options => ( | ||
| 13 | is => 'ro', | ||
| 14 | isa => t('NonEmptyStr'), | ||
| 15 | predicate => '_has_options', | ||
| 16 | ); | ||
| 17 | |||
| 18 | with qw( Code::TidyAll::Role::RunsCommand Code::TidyAll::Role::Tempdir ); | ||
| 19 | |||
| 20 | our $VERSION = '0.85'; | ||
| 21 | |||
| 22 | sub _build_cmd {'jshint'} | ||
| 23 | |||
| 24 | sub validate_file { | ||
| 25 | my ( $self, $file ) = @_; | ||
| 26 | |||
| 27 | my $output = $self->_run_or_die( $self->_config_file_argv, $file ); | ||
| 28 | if ( $output =~ /\S/ ) { | ||
| 29 | $output =~ s/^$file:\s*//gm; | ||
| 30 | die "$output\n"; | ||
| 31 | } | ||
| 32 | |||
| 33 | return; | ||
| 34 | } | ||
| 35 | |||
| 36 | sub _config_file_argv { | ||
| 37 | my $self = shift; | ||
| 38 | |||
| 39 | return unless $self->_has_options; | ||
| 40 | |||
| 41 | my $conf_file = $self->_tempdir->child('jshint.json'); | ||
| 42 | $conf_file->spew( | ||
| 43 | '{ ' . join( ",\n", map {qq["$_": true]} split /\s+/, $self->options ) . ' }' ); | ||
| 44 | |||
| 45 | return ( '--config', $conf_file ); | ||
| 46 | } | ||
| 47 | |||
| 48 | 1; | ||
| 49 | |||
| 50 | # ABSTRACT: Use jshint with tidyall | ||
| 51 | |||
| 52 | __END__ |