<commit_before>{-# LANGUAGE OverloadedStrings #-}
module Databrary.Web.JSHint
  ( checkJSHint
  ) where

import Control.Monad (mzero, when)
import Control.Monad.IO.Class (liftIO)
import qualified Data.ByteString.Char8 as BSC
import System.FilePath (takeExtensions)
import System.Posix.FilePath (splitFileName, addExtension)
import System.Posix.IO.ByteString (openFd, OpenMode(WriteOnly), defaultFileFlags, closeFd)
import System.Process (callProcess)

import Paths_databrary.Node
import Databrary.Files
import Databrary.Web
import Databrary.Web.Types
import Databrary.Web.Generate

checkJSHint :: WebGenerator
checkJSHint fo@(f, _)
  | takeExtensions (webFileRel f) == ".js" = do
    r <- fileNewer f fo
    when r $ liftIO $ do
      ht <- fmap snd <$> fileInfo h
      ft <- modificationTimestamp <$> getFileStatus f
      when (all (ft >) ht) $ do
        callProcess (binDir </> "jshint") [webFileAbs f]
        maybe
          (openFd h WriteOnly (Just 0o666) defaultFileFlags >>= closeFd)
          (\_ -> setFileTimestamps h ft ft)
          ht
    return r
  | otherwise = mzero
  where
  (d, n) = splitFileName $ webFileAbsRaw f
  h = d </> ('.' `BSC.cons` n `addExtension` ".hinted")<commit_msg>removed binDir<commit_after>{-# LANGUAGE OverloadedStrings #-}
module Databrary.Web.JSHint
  ( checkJSHint
  ) where

import Control.Monad (mzero, when)
import Control.Monad.IO.Class (liftIO)
import qualified Data.ByteString.Char8 as BSC
import System.FilePath (takeExtensions)
import System.Posix.FilePath (splitFileName, addExtension)
import System.Posix.IO.ByteString (openFd, OpenMode(WriteOnly), defaultFileFlags, closeFd)
import System.Process (callProcess)

import Paths_databrary.Node
import Databrary.Files
import Databrary.Web
import Databrary.Web.Types
import Databrary.Web.Generate

checkJSHint :: WebGenerator
checkJSHint fo@(f, _)
  | takeExtensions (webFileRel f) == ".js" = do
    r <- fileNewer f fo
    when r $ liftIO $ do
      ht <- fmap snd <$> fileInfo h
      ft <- modificationTimestamp <$> getFileStatus f
      when (all (ft >) ht) $ do
        callProcess ("jshint") [webFileAbs f]
        maybe
          (openFd h WriteOnly (Just 0o666) defaultFileFlags >>= closeFd)
          (\_ -> setFileTimestamps h ft ft)
          ht
    return r
  | otherwise = mzero
  where
  (d, n) = splitFileName $ webFileAbsRaw f
  h = d </> ('.' `BSC.cons` n `addExtension` ".hinted")
{'fraction_non_alphanumeric': 0.10875, 'fraction_numerical': 0.004166666666666667, 'mean_word_length': 3.5387523629489603, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5966668', 'n_tokens_mistral': 832, 'n_tokens_neox': 800, 'n_words': 219}