LoginSignup
2
0

More than 5 years have passed since last update.

.prettierrcのvalidationチェック

Last updated at Posted at 2017-12-31

schemastore.orgにホストされているJSON schemaを利用して行う

"trailingComma": "es6" <= こういうのをうっかりpushしないようにしたい

.prettierrcサンプル

.prettierrc
{
    "printWidth": 120,
    "tabWidth": 4,
    "singleQuote": true,
    "trailingComma": "es7"
}

validation実行

validate.js
const { get } = require('axios');
const { readFileSync } = require('fs');
const { Validator } = require('jsonschema');

const valid = new Validator();

(async () => {
    try {
        const result = valid.validate(
            JSON.parse(readFileSync('./.prettierrc', 'utf-8')),
            (await get('http://json.schemastore.org/prettierrc')).data
        );

        if (!result.errors) {
            console.log('no error!');
        } else {
            result.errors.forEach(e => console.log(e.stack));
        }
    } catch (err) {
        throw new Error(err);
    }
})();

出力例

instance does not match allOf schema <#/definitions/optionsDefinition> with 1 error[s]:
instance.trailingComma is not one of enum values: none,all,es5
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0