Skip to content

Commit

Permalink
fix: correct replace range (#3)
Browse files Browse the repository at this point in the history
* fix: correct replace range

fix #2

* CI: use GitHub Actions
  • Loading branch information
azu authored Jul 16, 2021
1 parent 6ea5b6d commit 340fc2b
Show file tree
Hide file tree
Showing 7 changed files with 1,982 additions and 1,583 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: test
on: [push, pull_request]
jobs:
test:
name: "Test on Node.js ${{ matrix.node-version }}"
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 12, 14, 16 ]
steps:
- name: checkout
uses: actions/checkout@v2
- name: setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: yarn install
- name: Test
run: yarn test
3 changes: 0 additions & 3 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# textlint-rule-date-weekday-mismatch [![Build Status](https://travis-ci.org/textlint-rule/textlint-rule-date-weekday-mismatch.svg?branch=master)](https://travis-ci.org/textlint-rule/textlint-rule-date-weekday-mismatch) [![textlint rule](https://img.shields.io/badge/textlint-fixable-green.svg?style=social)](https://textlint.github.io/)
# textlint-rule-date-weekday-mismatch [![Actions Status: test](https://github.com/textlint-rule/textlint-rule-date-weekday-mismatch.svg?branch=master)](https://travis-ci.org/textlint-rule/textlint-rule-date-weekday-mismatch) [![textlint rule](https://img.shields.io/badge/textlint-fixable-green/workflows/test/badge.svg)](https://github.com/textlint-rule/textlint-rule-date-weekday-mismatch.svg?branch=master)](https://travis-ci.org/textlint-rule/textlint-rule-date-weekday-mismatch) [![textlint rule](https://img.shields.io/badge/textlint-fixable-green/actions?query=workflow%3A"test")

textlint rule that found mismatch between date and weekday.

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
},
"homepage": "https://github.com/textlint-rule/textlint-rule-date-weekday-mismatch",
"devDependencies": {
"textlint-scripts": "^3.0.0"
"textlint-scripts": "^12.0.2"
},
"keywords": [
"textlintrule"
],
"dependencies": {
"chrono-node": "^1.2.5",
"moment": "^2.17.1"
"moment": "^2.29.1",
"textlint-tester": "^12.0.2"
}
}
}
4 changes: 2 additions & 2 deletions src/textlint-rule-date-weekday-mismatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function reporter(context, config = {}) {
const expectedWeekday = $moment.format(format);
if (maybeWeekdayText !== expectedWeekday) {
const fix = fixer.replaceTextRange(
[paddingIndex, paddingIndex + expectedWeekday.length],
[paddingIndex, paddingIndex + maybeWeekdayText.length],
expectedWeekday
);
report(node, new RuleError(`${actualTextAll} mismatch weekday.\n${actualTextAll} => ${chronoDate.text}${pairStartSymbol}${expectedWeekday}${pairEndSymbol}`, {
Expand All @@ -136,4 +136,4 @@ function reporter(context, config = {}) {
module.exports = {
linter: reporter,
fixer: reporter
};
};
18 changes: 15 additions & 3 deletions test/textlint-rule-date-weekday-mismatch-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const TextLintTester = require("textlint-tester");
import TextLintTester from "textlint-tester";

const tester = new TextLintTester();
// rule
const rule = require("../src/textlint-rule-date-weekday-mismatch");
Expand Down Expand Up @@ -32,6 +33,17 @@ tester.run("rule", rule, {
}
]
},
{
text: "2021-07-02 (Thursday)",
output: "2021-07-02 (Friday)",
errors: [
{
message: "2021-07-02 (Thursday) mismatch weekday.\n2021-07-02 (Thursday) => 2021-07-02 (Friday)",
line: 1,
column: 13
}
]
},
{
text: "2017年1月1日 (火)",
output: "2017年1月1日 (日)",
Expand Down Expand Up @@ -110,6 +122,6 @@ tester.run("rule", rule, {
}
]
},

]
});
});
Loading

0 comments on commit 340fc2b

Please sign in to comment.