Skip to content

tests(prettier): validate configuration against schema #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prettier-config-solidity",
"version": "1.5.2",
"version": "1.6.2",
"description": "conformant configuration for linting solidity files with prettier, based on offical solidity documentation",
"prettier": [
"prettier-solidity-config",
Expand Down
53 changes: 53 additions & 0 deletions tests/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const Ajv = require("ajv")
// options can be passed, e.g. {allErrors: true}
//const ajv = new Ajv()

//import schema from 'schema.json';
const schema = require('./schema/prettier.schema.json');


const configSolidity = {
arrowParens: 'always',
bracketSpacing: true,
jsxBracketSameLine: false,
jsxSingleQuote: false,
endOfLine: 'lf',
printWidth: 80,
singleQuote: true,
tabWidth: 2,
trailingComma: 'all',
quoteProps: 'as-needed',
proseWrap: 'always',
semi: true,
overrides: [
{
files: '*.sol',
options: {
printWidth: 80,
tabWidth: 4,
useTabs: false,
singleQuote: false,
bracketSpacing: true,
explicitTypes: 'always',
},
},
],
};


function isValid(schema, configSolidity) {
const ajv = new Ajv();
const valid = ajv.validate(schema, configSolidity);

if (!valid) {
console.log(ajv.errors);
return false;
}

return true;
console.log('Successfully Validated Configruation File');
}

//const validate = ajv.compile(schema)
//const valid = validate(configSolidity)
//if (!valid) console.log(validate.errors)