Coder Social home page Coder Social logo

markdownlint-rule-search-replace's People

Contributors

dependabot[bot] avatar maetveis avatar onkarruikar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

markdownlint-rule-search-replace's Issues

Allow per-rule ignores

When applying the formatting rules of mdn/content to mdn/translated-content, we ran into a slight issue regarding smart (curly) quotes with the Chinese locale. Apparently, it is grammatically accurate to use smart quotes in place of normal quotes, so the rule to search and replace smart quotes causes localization issues.

It would be great to see a filter option added, which is an object containing optional include and exclude properties, which are either a string or array of strings containing file globs for that rule to apply to or ignore. For example:

{
  "name": "curly-double-quotes",
  "message": "Don't use curly double quotes",
  "searchPattern": "/“|”/g",
  "replace": "\"",
  "searchScope": "text",
  "filter": {"exclude": "**/zh-cn/**"} // Ignore all Simplified Chinese files
},
{
  "name": "m-dash",
  "message": "Don't use '--'. Use m-dash — instead",
  "search": " -- ",
  "replace": "",
  "searchScope": "text",
  "filter": {"exclude": ["README.md", "**/es/**"]} // Ignore README.md in root, and all Spanish files
},
{
  "name": "em-dash",
  "message": "Don't use '--'. Use em-dash — instead",
  "search": " -- ",
  "replace": "",
  "searchScope": "text",
  "filter": {"include": "**/es/**"} // Only apply to Spanish files
},

Custom Rule Errors with `undefined`

Here is our .markdownlint.json file with a custom rule, per the documentation:
Screenshot 2023-02-09 at 12 29 39 PM

This is erroring out when actually linting a file:
Screenshot 2023-02-09 at 12 31 15 PM

I believe the error is occurring here, but I'm not able to debug it:

const stringToRegex = (str) => {
const pattern = (str.match(/\/(.+)\/.*/) || ["", "a^"])[1];
const flags = (str.match(/\/.+\/(.*)/) || ["", "g"])[1];
return new RegExp(pattern, flags);
};

Multi word searches without replacements cannot be specified from json or yaml

To make a rule with multiple search words without replacements the README suggests to use an array with undefined elements (a sparse array):

A list of words and corresponding list of replacements can be provided in a single rule:

{
  "default": true,
  "search-replace": {
    "rules": [
      {
        "name": "bad-spellings",
        "message": "Incorrect spelling",
        "search": ["e-mail", "wtf", "web site"],
        "replace": ["email", , "website"],
        "skipCode": false
      }
    ]
  }
}

But altough valid in javascript, this is not valid in JSON! Javascripts undefined doesn't exist in JSON (nor YAML), so this cannot be entered into the markdownlint configuration files, it can only be used when calling markdownlint from js.

JSON has null which maps to javascripts null, but setting replace to null results in the word being replaced by "null".

Add the ability to set a custom URL that is displayed in the error

This is a feature request to be able to define a custom URL for each rule in the config that is used when that rule shows an error.

Currently each error shows the URL of this repository:

https://github.com/OnkarRuikar/markdownlint-rule-search-replace/blob/main/rule.js#L139-L140

For my use case, the error is seen by people in GitHub pull requests that are not familiar with how markdownlint works. So when they are reading the error, a link to this repository doesn't help them.

Instead, if I was able to add custom URLs to either documentation or the rule definition in my config, they would be able to better understand the rule and how to fix the error.

Thanks for reading and your consideration! This is a helpful tool—I appreciate you working on it 💖

exception when using searchPattern

searchPattern: "/(?<=[\\w\\d ])\\n(?=[\\w\\d])/g"

results in:

search-replace Custom rule [This rule threw an exception: Property 'range' of onError parameter is incorrect.]

what's interesting is that the rule actually seems to work, it's just a problem with the output. this rule is meant to catch linebreaks within a sentence. e.g.

The following line
break should not exist.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.