imp!: check ordereddates: drop --date2 support; check primary dates only
date2 is a deprecated feature and was getting in the way, so has been dropped from the ordereddates check, simplifying it.
This commit is contained in:
parent
afe9e2c6f4
commit
4cbf72ab1f
@ -9,34 +9,33 @@ import Text.Printf (printf)
|
|||||||
import qualified Data.Text as T (pack, unlines)
|
import qualified Data.Text as T (pack, unlines)
|
||||||
|
|
||||||
import Hledger.Data.Errors (makeTransactionErrorExcerpt)
|
import Hledger.Data.Errors (makeTransactionErrorExcerpt)
|
||||||
import Hledger.Data.Transaction (transactionFile, transactionDateOrDate2)
|
import Hledger.Data.Transaction (transactionFile)
|
||||||
import Hledger.Data.Types
|
import Hledger.Data.Types
|
||||||
import Hledger.Utils (textChomp)
|
import Hledger.Utils (textChomp)
|
||||||
|
|
||||||
journalCheckOrdereddates :: WhichDate -> Journal -> Either String ()
|
journalCheckOrdereddates :: Journal -> Either String ()
|
||||||
journalCheckOrdereddates whichdate j = do
|
journalCheckOrdereddates j = do
|
||||||
let
|
let
|
||||||
-- we check date ordering within each file, not across files
|
-- we check date ordering within each file, not across files
|
||||||
-- note, relying on txns always being sorted by file here
|
-- note, relying on txns always being sorted by file here
|
||||||
txnsbyfile = groupBy (\t1 t2 -> transactionFile t1 == transactionFile t2) $ jtxns j
|
txnsbyfile = groupBy (\t1 t2 -> transactionFile t1 == transactionFile t2) $ jtxns j
|
||||||
getdate = transactionDateOrDate2 whichdate
|
compare' a b = tdate a <= tdate b
|
||||||
compare' a b = getdate a <= getdate b
|
|
||||||
(const $ Right ()) =<< (forM txnsbyfile $ \ts ->
|
(const $ Right ()) =<< (forM txnsbyfile $ \ts ->
|
||||||
case checkTransactions compare' ts of
|
case checkTransactions compare' ts of
|
||||||
FoldAcc{fa_previous=Nothing} -> Right ()
|
FoldAcc{fa_previous=Nothing} -> Right ()
|
||||||
FoldAcc{fa_error=Nothing} -> Right ()
|
FoldAcc{fa_error=Nothing} -> Right ()
|
||||||
FoldAcc{fa_error=Just t, fa_previous=Just tprev} -> Left $ printf
|
FoldAcc{fa_error=Just t, fa_previous=Just tprev} -> Left $ printf
|
||||||
("%s:%d:\n%s\nOrdered dates checking is enabled, and this transaction's\n"
|
("%s:%d:\n%s\nOrdered dates checking is enabled, and this transaction's\n"
|
||||||
++ "date%s (%s) is out of order with the previous transaction.\n"
|
++ "date (%s) is out of order with the previous transaction.\n"
|
||||||
++ "Consider moving this entry into date order, or adjusting its date.")
|
++ "Consider moving this entry into date order, or adjusting its date.")
|
||||||
f l ex datenum (show $ getdate t)
|
f l ex (show $ tdate t)
|
||||||
where
|
where
|
||||||
(_,_,_,ex1) = makeTransactionErrorExcerpt tprev (const Nothing)
|
(_,_,_,ex1) = makeTransactionErrorExcerpt tprev (const Nothing)
|
||||||
(f,l,_,ex2) = makeTransactionErrorExcerpt t finderrcols
|
(f,l,_,ex2) = makeTransactionErrorExcerpt t finderrcols
|
||||||
-- separate the two excerpts by a space-beginning line to help flycheck-hledger parse them
|
-- separate the two excerpts by a space-beginning line to help flycheck-hledger parse them
|
||||||
ex = T.unlines [textChomp ex1, T.pack " ", textChomp ex2]
|
ex = T.unlines [textChomp ex1, T.pack " ", textChomp ex2]
|
||||||
finderrcols _t = Just (1, Just 10)
|
finderrcols _t = Just (1, Just 10)
|
||||||
datenum = if whichdate==SecondaryDate then "2" else "")
|
)
|
||||||
|
|
||||||
data FoldAcc a b = FoldAcc
|
data FoldAcc a b = FoldAcc
|
||||||
{ fa_error :: Maybe a
|
{ fa_error :: Maybe a
|
||||||
|
|||||||
@ -93,13 +93,13 @@ parseCheckArgument s =
|
|||||||
-- | Run the named error check, possibly with some arguments,
|
-- | Run the named error check, possibly with some arguments,
|
||||||
-- on this journal with these options.
|
-- on this journal with these options.
|
||||||
runCheck :: CliOpts -> Journal -> (Check,[String]) -> IO ()
|
runCheck :: CliOpts -> Journal -> (Check,[String]) -> IO ()
|
||||||
runCheck CliOpts{reportspec_=ReportSpec{_rsReportOpts=ropts}} j (chck,_) = do
|
runCheck _opts j (chck,_) = do
|
||||||
d <- getCurrentDay
|
d <- getCurrentDay
|
||||||
let
|
let
|
||||||
results = case chck of
|
results = case chck of
|
||||||
Accounts -> journalCheckAccounts j
|
Accounts -> journalCheckAccounts j
|
||||||
Commodities -> journalCheckCommodities j
|
Commodities -> journalCheckCommodities j
|
||||||
Ordereddates -> journalCheckOrdereddates (whichDate ropts) j
|
Ordereddates -> journalCheckOrdereddates j
|
||||||
Payees -> journalCheckPayees j
|
Payees -> journalCheckPayees j
|
||||||
Recentassertions -> journalCheckRecentAssertions d j
|
Recentassertions -> journalCheckRecentAssertions d j
|
||||||
Tags -> journalCheckTags j
|
Tags -> journalCheckTags j
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user