Skip to content

Commit

Permalink
Merge pull request #1032 from prettier-solidity/slang
Browse files Browse the repository at this point in the history
Slang
  • Loading branch information
Janther authored Sep 18, 2024
2 parents 889a5bb + 22edc8e commit 0fded41
Show file tree
Hide file tree
Showing 492 changed files with 15,285 additions and 660 deletions.
16 changes: 6 additions & 10 deletions .c8rc
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
{
"check-coverage": true,
"branches": 99,
"lines": 100,
"functions": 100,
"statements": 100,
"exclude": ["/node_modules/", "/src/prettier-comments/"],
"include": [
"src/**/*.js",
"!src/prettier-comments/**/*.js",
"!src/common/backward-compatibility.js"
],
"branches": 90,
"lines": 90,
"functions": 90,
"statements": 90,
"exclude": ["/node_modules/"],
"include": ["src/**/*.ts", "!src/slang-utils/backward-compatibility.ts"],
"reporter": ["lcov", "text"],
"temp-dir": "./coverage/"
}
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
coverage/**/*.js
dist/**/*.cjs
dist/**/*.js
tests/**/*.snap
tests/format/**/*.sol
tests/format/Markdown/Markdown.md
tests/format/RespectDefaultOptions/respect-default-options.js
Expand Down
44 changes: 35 additions & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,42 @@
"env": {
"jest": true
},
"extends": ["airbnb-base", "prettier"],
"globals": {
"run_spec": false
},
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
"runFormatTest": "readonly"
},
"rules": {
"import/extensions": "off",
"import/prefer-default-export": "off"
}
"no-console": ["error", { "allow": ["warn"] }]
},
"overrides": [
{
"files": ["**/*.ts"],
"extends": [
"prettier",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/stylistic",
"plugin:@typescript-eslint/recommended-type-checked"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"parserOptions": {
"project": ["tsconfig.json"]
},
"rules": {
"@typescript-eslint/explicit-function-return-type": "error"
}
},
{
"files": ["**/*.*js"],
"extends": ["airbnb-base", "prettier"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"import/extensions": "off",
"import/prefer-default-export": "off",
"class-methods-use-this": "off"
}
}
]
}
42 changes: 21 additions & 21 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ jobs:
- name: lint
run: npm run lint

test_bundle:
name: Test production
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'
- name: Install
run: npm install
- name: Build
run: npm run build
- name: Build test app
run: npm run build:test
- name: Run tests
run: npm run test:standalone
# test_bundle:
# name: Test production
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-node@v3
# with:
# node-version: 16
# cache: 'npm'
# - name: Install
# run: npm install
# - name: Build
# run: npm run build
# - name: Build test app
# run: npm run build:test
# - name: Run tests
# run: npm run test:standalone

test_prettier_v2:
name: Prettier V2
Expand All @@ -56,10 +56,10 @@ jobs:
run: npm run build
- name: Downgrade Prettier to V2
run: npm install [email protected]
- name: Build test app
run: npm run build:test
- name: Run standalone tests
run: npm run test:standalone tests/format tests/integration tests/unit/prettier-version
# - name: Build test app
# run: npm run build:test
# - name: Run standalone tests
# run: npm run test:standalone

test_linux:
name: Test on Linux with Node ${{ matrix.node }}
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 prettier-solidity
Copyright (c) 2024 prettier-solidity

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

A [Prettier plugin](https://prettier.io/docs/en/plugins.html) for automatically formatting your [Solidity](https://github.com/ethereum/solidity) code.

## Nomic Foundation's Slang

Nomic Foundation has put a lot of effort in providing a set of compiler APIs that helped us rethink our approach to parsing and rely on their flexibility, detail oriented solution and continuos support of new and old Solidity syntaxes.

Since v2.0.0 this package will ship with the Slang parser and this change must be implemented in existing configurations by replacing `parser: 'solidity-parse'` with `parser: 'slang-solidity'`.

## Installation and usage

### Using in NodeJS
Expand Down Expand Up @@ -40,7 +46,7 @@ Or you can use it as part of your linting to check that all your code is prettif

> Prettier Solidity only works with valid code. If there is a syntax error, nothing will be done and a parser error will be thrown.
### Using in the Browser
### ~~Using in the Browser~~ _Disabled during v2.0.0-beta_

_Added in v1.1.0_

Expand All @@ -61,7 +67,7 @@ We follow Prettier's strategy for populating their plugins in the object `pretti
<script>
async function format(code) {
return await prettier.format(code, {
parser: 'solidity-parse',
parser: 'slang-solidity',
plugins: [solidityPlugin]
});
}
Expand All @@ -73,7 +79,7 @@ We follow Prettier's strategy for populating their plugins in the object `pretti

For more details and please have a look at [Prettier's documentation](https://prettier.io/docs/en/browser.html).

### Creating a package for the Browser
### ~~Creating a package for the Browser~~ _Disabled during v2.0.0-beta_

_Added in v1.2.0_

Expand All @@ -85,7 +91,7 @@ import solidityPlugin from 'prettier-plugin-solidity/standalone';

async function format(code) {
return await prettier.format(code, {
parser: "solidity-parse",
parser: "slang-solidity",
plugins: [solidityPlugin],
});
}
Expand All @@ -106,7 +112,7 @@ The following is the default configuration internally used by this plugin.
{
"files": "*.sol",
"options": {
"parser": "solidity-parse",
"parser": "slang-solidity",
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
Expand Down
17 changes: 8 additions & 9 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const TEST_STANDALONE = Boolean(process.env.TEST_STANDALONE);
const testMatch = [
'<rootDir>/tests/format/**/jsfmt.spec.js',

'<rootDir>/tests/unit/**/*.test.js'
];
const testMatch = ['<rootDir>/tests/format/**/format.test.js'];

if (TEST_STANDALONE) {
testMatch.push('<rootDir>/tests/integration/**/*.test.js');
testMatch.push(
'<rootDir>/tests/integration/**/*.test.js',
'<rootDir>/tests/unit/prettier-version/**/*.test.js'
);
} else {
testMatch.push('<rootDir>/tests/unit/**/*.test.js');
}

export default {
runner: 'jest-light-runner',
setupFiles: ['<rootDir>/tests/config/setup.js'],
setupFiles: ['<rootDir>/tests/config/format-test-setup.js'],
snapshotSerializers: [
'jest-snapshot-serializer-raw',
'jest-snapshot-serializer-ansi'
],
testEnvironment: 'node',
// ignore console warnings in TEST_STANDALONE
silent: TEST_STANDALONE,
testPathIgnorePatterns: TEST_STANDALONE
Expand All @@ -27,7 +27,6 @@ export default {
]
: [],
testMatch,
transform: {},
watchPlugins: [
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname'
Expand Down
Loading

0 comments on commit 0fded41

Please sign in to comment.